1

String - try the Club for 1 Dollar

I am trying to get 3 values from the string :

quantity - try the

metal - Club

value - Dollar

but I am getting lub for metal. Regex I tried :

(?<quantity>[\s\S]*?)[A-Z](?<metal>[\S]*?)\sfor\s(?<value>[\d]+?)\sDollar

I am not able to correct the regex. Can anybody help me with this?

4
  • What is your regex flavor? Commented Dec 8, 2015 at 19:27
  • Thanks for the edit...I am not sure what flavor means..I am using it in C# if that helps Commented Dec 8, 2015 at 19:29
  • @sln Thanks a lot . It worked perfectly. Commented Dec 8, 2015 at 19:33
  • I'll post it as an answer in case anybody will use it. Commented Dec 8, 2015 at 19:34

1 Answer 1

1

This [A-Z] is matching C. Change it to (?=[A-Z])

(?<quantity>[\s\S]*?)(?=[A-Z])(?<metal>[\S]*?)\sfor\s(?<value>[\d]+?)\sDollar

Output:

 **  Grp 0            -  ( pos 0 , len 25 ) 
try the Club for 1 Dollar  
 **  Grp 1 [quantity] -  ( pos 0 , len 8 ) 
try the   
 **  Grp 2 [metal]    -  ( pos 8 , len 4 ) 
Club  
 **  Grp 3 [value]    -  ( pos 17 , len 1 ) 
1  
Sign up to request clarification or add additional context in comments.

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.