Tuesday, December 27, 2016

Regular Expression Basics - 2

We are continuing the regular expression basics with this post
  
/(cbc|dnn)/g
You can "OR" the characters with the "|" metacharacter

Watchdnn&cbcforthenews

/h(ale|asan)/g

Don'tcomewithhaleorhasan99

/(Java|Lava)Script/g

LearnJavaScriptinsteadofLavaScript!

----

/^wow/g

The above regular expression matches the strings beginnign with wow.

wow!great! 100?wow!! woxxw!whatchataling?wow

 ----

/wow$/g

The above regular expression matches the strings endinig with wow.

wow!great! 100?wow unbelievable!wow!

----

/x(?=y)/g

The above regular expression matches "x" if it is followed by "y".

fixitorleavethegataxy isittoxic?orfoxy

----

/x(?!y)/g

The above regular expression matches "x" if it is not followed by "y".

fixitorleavethegataxy isittoxic?orfoxy laxairport

----

/^[0-9]{4}-[0-9]{3}-[0-9]{4}$/g

0555-444-2233 312-444-7766 0462-6667788 0462-222-0099

----

/^\w*@\w*\.\w*$/g

abc@def.com abidik99@gubidik.com 
 
----

/grea?t/g

0 or 1 "a"

great grept gret greet greaaat!

----

/bo+t/g

1 or more "o"

boot booth bot booots orbots say_booooooots

----

/le*d/g

 0 or more "e"

led leeeed gled gleed fled fleed fleeeeed hold told folder foleds

 

No comments:

Post a Comment