tags:

views:

28

answers:

2

Say i have a string as follows

' *my test string 1 111:222:444: &EVERYTHING INSIDE THIS REGARLESS OF CHAR OR INT£ This is a test string (123456789)'

I want to return every thing inside & and the £ sign or match it.

Any body could help me with the regex expression for this.

+2  A: 

You might have to be careful of character encodings, but apart from that the following should work:

 /&.*?£/

Edit: Updated to stop on the first £.

Mark Byers
+1  A: 

Is it possible for there to be multiple £ characters in the string? If so, you need to be careful about greediness. Mark's pattern will not stop on the first £ but rather the last £ in the string. You may want a more restricted pattern, like

/&([^£]*)£/

That pattern will stop on the first £ after the & in your string. It also uses a captured group so you can extract just the text you want. There is one other thing to note here, which is if there's multiple &'s before the £, this will start capturing at the first &. If you want to capture at the latest & before the £ you may want this pattern instead:

/&([^£&]*)£/
Kevin Ballard