regex - What is the meaning of this regular expression? -


/\s/g 

what meaning of above regular expression?

it means search whitespace character. /g means nothing in single regex search.

edit: wanted dissection. here goes.

/ 

start regular expression.

\ 

a backslash used either escape special characters (that, on own, change how regular expression operates, how + used denote "match 1 or more of character right before me") or start metacharacter. in case, it's used start metacharacter:

s 

coupled backslash, s means "match whitespace character". whitespace characters spaces, tabs, newlines, , other such characters.

/ 

end regular expression. or it?

g 

hey what's going on here, canspice? thought said / ended regular expression? kind reader, what's called "regular expression modifier". means "search globally", , modifies behaviour of regular expression. in perl, example, means "store position of match , start position again if run match again", can things like:

my $x = "cat dog house"; while ($x =~ /(\w+)/g) {     print "word $1, ends @ position ", pos $x, "\n"; } 

...which prints out:

word cat, ends @ position 3 word dog, ends @ position 7 word house, ends @ position 13 

for more, please see this tutorial.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -