Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="main">
    <div class="row">
        <!-- Input -->
        <div class="col s5 offset-s1">
            <div class="row">
                <div class="col s12">
                    <div class="mainBoxWrapper input-field">
                        <textarea id="ipInput" class="materialize-textarea" placeholder="paste your IP addresses here, one per line"></textarea>
                        <label for="ipInput">IP Addresses Input</label>
                        <div class="toolbar">
                            <div class="button btn red clear">Clear</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Output -->
        <div class="col s5 offset-s025">
            <div class="row">
                <div class="col s12">
                    <div class="mainBoxWrapper input-field">
                        <textarea id="regexOutput" class="materialize-textarea" placeholder="Regex output will appear here..."></textarea>
                        <label for="regexOutput">Regex Output</label>
                        <div class="toolbar">
                            <div class="button btn copyOutput" data-clipboard-target="#regexOutput">Copy to Clipboard</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col s2 offset-s2">
            <div class="button btn green" id="demoButton">Demo</div>
        </div>
    </div>
</div>
            
          
!
            
              #ipInput,#regexOutput {
  min-height: 200px;
  margin-top: 20px;
}
.mainBoxWrapper {
  border: 1px solid black;
  padding: 20px;
}
#regexOutput {
  cursor: not-allowed;
}
.toolbar {
  width: 100%;
  text-align: center;
}
.offset-s05 {
    margin-left: calc(100% / 24) !important;
}
.offset-s025 {
    margin-left: calc(100% / 48) !important;
}
label[for] {
    margin-left: 5px;
}
.options {
    margin: 10px 0px;
    border-top: 1px dashed black;
    border-bottom : 1px dashed black;
}
.row {
    margin-bottom: 5px !important;
}
            
          
!
            
              var ipInputField = document.getElementById('ipInput');
var regexOutputField = document.getElementById('regexOutput');

function generateOutput() {
    var ipAddresses = [];
    var input = ipInputField.value;
    var output = '';
    // Process line by line
    input.split(/\r|\n|\r\n/).forEach(function(line){
       if (line!==''){
           var ipAddress = line.trim().toLocaleLowerCase();
           if (ipAddresses.indexOf(ipAddress)==-1){
               var linePattern = ipAddress;
               // Escape periods
               linePattern = linePattern.replace(/\./gim,"\\.");
               // Prefix line with start char
               linePattern = "^" + linePattern;
               // Suffix line with end char
               linePattern = linePattern + "$";
               // Append to continuous pattern, suffixing with pipe (OR) char if necessary
               output = output + (output!=='' ? '|' : '') + linePattern;
           }
       } 
    });
    // Finally, set output field
    regexOutputField.value = output;
}


function runDemo(){
    ipInputField.value = '216.3.128.12\r\n19.117.63.126\r\n2001:0db8:85a3:0000:0000:8a2e:0370:7334\r\n';
    generateOutput();
}

// Add event listeners
ipInputField.addEventListener('blur', generateOutput);
ipInputField.addEventListener('change', generateOutput);
ipInputField.addEventListener('keyup', generateOutput);
regexOutputField.addEventListener('click', function (evt) {
    evt.target.select();
});

var clipboard = new ClipboardJS('.copyOutput');

document.querySelector('.button.clear').addEventListener('click', function () {
    ipInputField.value = '';
    generateOutput();
});

document.getElementById('demoButton').addEventListener('click',function(evt){
    runDemo();
});

// generate on load
generateOutput();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console