-1

I am struggling with what is most probably a very simple regular expression.

Consider this the text I wish to evaluate:

??Company=My Company Name Ltd??Address= 29 Acacia Road, Nuttytown, AA1 9AA??Description=A very rambling description here... goes on for a bit and then somemore??E-mail=bert@bertswork.com??Version=Super Plus??Expiration date=01/01/2026??First name=Bert??Last name=Bloggs??

I want to extract the string for My Company Name Ltd that is between the Company= and the ??Address= tags.

Please can some kind soul put me out of my misery!

halfer
  • 19,824
  • 17
  • 99
  • 186
mc1903
  • 11
  • 2

2 Answers2

0

Although we usually want to see what you've tried, I've been in your situation - A complete noob and not knowing even where to start, so hope this helps...

Since you know each tag starts with a ?, you can use the following:

\?\?Company\=([^?]*)

This basically says:

  1. It starts with ??Company=
  2. Take all the characters after that until you find the next ? character and place them in a capture group.

Hope that does the trick

John Bustos
  • 19,036
  • 17
  • 89
  • 151
  • Thank you. I am glad you didn't ask what I had tried first before helping me. For the record: I tried google and realised I was not 'getting it'. I then had a cup of tea and a cake to make myself feel better. I then asked the community of experts and you came to my rescue. Cheers :-) – mc1903 Aug 14 '15 at 13:37
0

You can try this

/(?<=\?{2}Company=)(.*?)(?=\?{2})/

I used lookbehind (?<=) and look ahead (?=) so that ??Company= and ?? is not included in the match.

Regex

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54