1

How i can cut in my string this

&ertert&User=3435&5454&Parameters=asasasa

I want to see only 3435 I have this already , but i don't know how to cut only 3435

&User=(\d+)
4
  • Do you want specifically 3435, or do you want the first set of numbers? Commented Nov 28, 2014 at 8:16
  • 1
    Just extract the number from the capturing group. Commented Nov 28, 2014 at 8:18
  • What you did should work. How do you retrieve the result at the end ? Usually, the result of a regex matching is an array with first element the entire matched pattern and next all the captured groups. Commented Nov 28, 2014 at 8:18
  • yes i want only numbers or text after &User=, but only that that text until next &. For example &ertert&User=3435&LALAL&Parameters=asasasa only 3435 , but this could be also text not just numbers Commented Nov 28, 2014 at 8:22

1 Answer 1

3

You could use lookaheads and behinds provided you've got their support as you've not mentioned the language.

/(?<=User=).+?(?=&)/

The above regex will only match 3435

The lookbehind (?<=User=) is to make sure the number what we are trying to match is preceded with the token provided in the look behind. In this case User=

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

3 Comments

doesn't work. I need this for ms sql .For example &ertert&User=3435&LALAL&Parameters=asasasa only 3435 , but this could be also text not just numbers
try here regexr.com. Put my string and try yours regex. For me it doesn't work
@John what's wrong with printing the group index 1?

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.