regex help

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
 
A

Arne Vajhøj

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 / !
 
T

Tem

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
 
A

Arne Vajhøj

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

Regex help 2
regex help 5
Difficulty with Regex pattern to validate a string 11
Counting regex expressions 3
regex help 3
Regular expression 3
Regex to find a string 4
Help with Regex in CSharp 11

Top