Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                #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;
}
              
            
!

JS

              
                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

Console