2

I'm trying to match a space in Postgres using substring.

I currently have: substring((data)::text from '(?:"name":")([a-zA-Z0-9._-]*)'),

The response of data would look like: "name":"John Smith"... I want to match the full name, but sadly I seem to only be matching John. I tried adding \s without any luck. Any idea what I'm doing wrong?

1 Answer 1

3

Postgresql regex doesn't have any problem with \s. So I assume you have used the \s at the end of your regex just after the hyphen(-) and it made all the difference. For example

([a-zA-Z0-9._-\s]*)
              ^----- you see the hyphen here? it is the problem.

Inside a regex character-class [] a-z means any character from a to z.

So you have two solutions.

Escaping the hyphen with \

([a-zA-Z0-9._\-\s]*)

or, placing the \s at the elsewhere, lets say at the beginning.

([\sa-zA-Z0-9._-]*)

Now try!

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.