MysteryDev
MysteryDev

Reputation: 638

Regular Expression, Select word between two words

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!

Upvotes: 14

Views: 41088

Answers (4)

johnanthonygreen
johnanthonygreen

Reputation: 7

Here is a regex that can find a guid inbetween anything guid anything or same around this is using dot net syntax and named capture with back reference. The anything capture syntax (.*?) is reused before and after the guid. So if there is an identifier somewhere in a Pat element or a App element this will find all of either.

[<](?<PatOrApt>Pat|App)[>](.*?)59358d09-8acd-4635-a019-1cbf9e1ed2db(.*?)[<][/]\k<PatOrApt>[>]

Upvotes: 0

jackcogdill
jackcogdill

Reputation: 5122

This should work if you get the first group:

\w+\s*(.+)\s*:

Upvotes: 0

John Woo
John Woo

Reputation: 263703

another alternative is to use this pattern

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

See Lookahead and Lookbehind Zero-Width Assertions

Upvotes: 14

MitziMeow
MitziMeow

Reputation: 655

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

Upvotes: 2

Related Questions