I have a text like this.
Mr John Smith , Mr James Smith +(21)-(21)-12345678, 12345678, 12345678 +(21)-12345678, 12345678, 12345678 SomeTextHereAlso +(21)-(22)-12345678 www.somewebaddress.co.uk Some Title, Some Place , Some Town,Some Suburb, City - 100000
I want to extract each of these strings using regex in javascript. I found some examples and this morning they worked. Now I don’t know why they don’t work any more.
To extract
Mr John Smith , Mr James Smith
I used this.
/\S(.*)\+/ and /\S(.*?)\+/
This didn’t work. I can’t figure out why.
To extract this
+(21)-(21)-12345678, 12345678, 12345678 +(21)-12345678, 12345678, 12345678 SomeTextHereAlso +(21)-(22)-12345678
I used this.
/\+(.*)(?=www.)/
This did work.
And for url I used
/www(.*?)(?=\s\s)/
And this works too.
The only problem is the first example that should extract all the characters until the first + but it extracts all the characters until the last +.
I checked on http://gskinner.com/RegExr/?2tr5t and the examples I showed here work. Are there any more similar examples that could help me since I looked into the code and didn’t find any error.
If regex is fine then how can I use IndexOf() method for this example to extract what I want?
You can try
[^+]+or more specifically^[^+]+