regex help

  • Thread starter Thread starter Tem
  • Start date Start date
T

Tem

i need a regex that matches either
/ABC/
or
/ABC/DEF/

I came up with
/(.*)/(.*)/

how do i make the second part optional?
thx
Tem
 
Tem said:
i need a regex that matches either
/ABC/
or
/ABC/DEF/

I came up with
/(.*)/(.*)/

how do i make the second part optional?

? and ?? means 0 or 1 occurrences.

Arne

PS: . also match / !
 
I tried

/(.*)/?(.*)?/

to match

/ABC/
/ABC/DEF/

/ABC/ returned ABC and null which is correct
but /ABC/DEF/ returned ABC/DEF and null
is should return ABC and DEF

thanks
 
Tem said:
I tried

/(.*)/?(.*)?/

to match

/ABC/
/ABC/DEF/

/ABC/ returned ABC and null which is correct
but /ABC/DEF/ returned ABC/DEF and null
is should return ABC and DEF

Did you note the PS ?

Try with [^/]* instead of .* !

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top