1

I'm trying to write a regular expression in javascript to catch all named parameters in PostgreSQL string to put them in table

lets say we have

var query="SELECT table.data FROM table JOIN table2 ON table2.id=table.id_tab2 WHERE table2.field <> :parm1::int GROUP BY table.data HAVING table.data position(:docType::text in document_type) <> 0

var tab=new Array();

//

I need rs to put into tab all parameters: "param1::int" and "docType::text" I tried do it myself but with no success :( http://regexr.com?31nok

4 Answers 4

1

something like this? :(\w+::\w+)

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

3 Comments

I saw - and _ in that character class, which \w won't match. Are those characters allowed in postgres named parameters?
@Qsario: in what character class? BTW, dash (-) is not allowed in postgresql typenames as far as i know, and underscore is matched by \w. i don't see a problem here.
I was looking at his original character class in regexr. And it appeared that \w wasn't matching _ there, but I might just have been tired.
1

and (:[a-zA-Z0-9]+::[a-zA-Z0-9]+)

1 Comment

it amost what i wonted. Difference is, thay i need those parameters without : on begin tried with :([a-z0-9_-]+::[a-z0-9_-]+) ,but effect is the same
1

There can be weird things between a-Z, so just use [a-z] with case insensitive or [a-zA-Z]. I think you probably want a global match (find all results). Multi-line is something else, it makes . match \n which doesn't help you that I can see. Try this: http://regexr.com?31not

Comments

0

when i try :([^: ]+::[^: ]+) and (:[^: ]+::[^: ]+) i see no difference- colon is in match in both casec.

However i found some other way

(?!:)([a-z0-9_-]+::[a-z0-9_-]+)

works perfectly. first part (?<=:) determine "Matches a group before your main expression without including it in the result."

Thanks you all for your answers ;)

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.