6

I have the following regex:-

^(?:\[ [^\]]+ \]) ([\-\£]{1,2}[0-9]+\.[0-9][0-9]?)?

And the following text:-

John Doe
+++++++++++++++++++++++++++++++++++++++++++
Blah blah
+++++++++++++++++++++++++++++++++++++++++++
[ √ ] £3.00 Red
[ √ ] £2.00 Blue
[ √ ] £55.55 Yellow
[ √ ] -£41.75 PAYMENT
[ √ ] £5.00 Green
[ √R ] £10.00 Pink
+++++++++++++++++++++++++++++++++++++++++++
Belugh
+++++++++++++++++++++++++++++++++++++++++++
Blah blah
Blah

The regex works ok and matches:-

£3.00
£2.00
£55.55
-£41.75
£5.00
£10.00

What I want to do though is to have the regex match the '£' but not return it in the capturing group.

So the results would be like this:-

3.00
2.00
55.55
-41.75
5.00
10.00

The important bit is the '-' character which should remain, but occurs before the '£' character.

Theres a fiddle here

1
  • 3
    That's not possible within the regex, use your environments capabilities to go through the matches and "clean up" anything you don't want. Regexes might help with the cleaning up, but I don't think you can do this with 1 regex. Commented Aug 25, 2014 at 9:48

2 Answers 2

5

Best you can do is this:

^(?:\[ [^\]]+ \]) (-?)[\£]([0-9]+\.[0-9][0-9]?)?

And then extract group 1 and group 2 from the matches and append them in the language/environment you're working in.

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

I actually prefer debuggex.com, particularly when doing more complicated stuff. But regex101 has some nice features too :)
0

I did this by including the "£" in the capture group and then simply replacing that symbol with "nothing" from the matched results in the language I'm working in.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.