ip: 3.144.235.141 DKs blog - Regular Expressions examples

DK's Blog

Regular Expressions

Regular expression to catch HTML tags, could be used to strip tags

(<[^>]+>)

 


Regular expression to validate email:

^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$

 


Regular expression to validate MAC address

([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}

 


Regular expression to validate IP address

find IP address, example 12.34.56.78
 
(([01]\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\.){3}([01]\d\d|2[0-4]\d|25[0-5]|\d\d|\d)
 
 

Put dots (thousands devider) in middle of every 3 digit

here is example 1234567890 -> 1.234.567.890

(\d)(?=(\d{3})+(?!\d))

replace with $1\.

 


How to find double lines occuring (must be one after another) in text

here is example of text file:

blahblah
blahblah2
blahblah2
blahblah3
blahblah4

and you want:

blahblah
blahblah2

blahblah3
blahblah4

 

Here is regexp;

^(.*?)$\n(?=^\1$)

replace with empty string and that line will be empty, if there is space on one of lines regexp will not highlight that line as duplicate!

 


 

 

@2016