I have a string that can be either
"MyName (ctid 5555)"
or
"OtherName (id 555-5555-5555-555)"
I tried to write a regex to fetch ctid or id, like so:
"(?<=ctid=).+(?=))"
Checking here gave 0 results.
What’s wrong with my syntax?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that a ctid is always 4 digits, and an id is always 3-4-4-3 digits, and that either way it is enclosed in round brackets, I would do:
This adds named groups and does validity checking at the same time. For example, you can use
match.Groups['ctid'].valueto get the ctid value, or['id']to get the id value. Because there is validity checking, you’ll never get (what I am assuming is) an invalid id like “(id 123)” (since it doesn’t have the 3-4-4-3 pattern).