Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression, Select word between two words

Tags:

regex

I'm reallllly new to regex and I need some help. I tried figuring out myself but had no luck!

I am trying to select text between 2 strings (character for the last string)

ie:

word word2 :

I am trying to select "word2" between word and :

thanks!

like image 789
MysteryDev Avatar asked Dec 26 '12 03:12

MysteryDev


People also ask

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.

What does (? I do in regex?

(? i) makes the regex case insensitive. (? c) makes the regex case sensitive.

What is the difference between \b and \b in regular expression?

Using regex \B-\B matches - between the word color - coded . Using \b-\b on the other hand matches the - in nine-digit and pass-key .


2 Answers

another alternative is to use this pattern

(?<=word\s).*(?=\s:)

See Lookahead and Lookbehind Zero-Width Assertions

like image 51
John Woo Avatar answered Nov 26 '22 03:11

John Woo


/word (.*?) \:/ this should do the trick

like image 40
MitziMeow Avatar answered Nov 26 '22 04:11

MitziMeow