1

I have following String

Copy(objid1,objid2)

and i am using following regex for match

objid(?<id>\d{0,3})

however i looking output objid2 and this regex returns objid1.

Is there any change would i do to find my desired output. I thought that i will return all matched sub strings but returns only first one However i need only last matched sub string.

I don't want to use any sub string function as i don't know exact length to find .

Thanks in advance.

Edit:

Please see my try.

Match output = Regex.Match("Copy(objid1,objid2)", @".*(objid(?<id>\d{0,3}))", RegexOptions.Singleline | RegexOptions.IgnoreCase); //objid(?<id>\d{0,3})

                    if (output.Success)
                    {
                        String ProcessString = ((System.Text.RegularExpressions.Capture)(output.Groups[0])).Value;//output.Value;
    }

2 Answers 2

1

Put a .* before the pattern you mentioned inorder to get the last match.

@".*(objid(?<id>\d{0,3}))"

DEMO

Get the string you want from group index 1.

To get a last match in the multiline string, you need to enable DOTALL modifier.

(?s).*(objid(?<id>\d{0,3}))

DEMO

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

3 Comments

This returns me String Copy(objid1,objid2 not objid2
print the group index 1 instead of index 0.
that is change Groups[0] to Groups[1]
1
,objid(?<id>\d{0,3})(?![^,)]*,)

Try this.See demo.

http://regex101.com/r/lZ5mN8/26

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.