small Reg exp prob

  • Thread starter Thread starter Lasse Edsvik
  • Start date Start date
L

Lasse Edsvik

Hello

I was wondering how to match car and the rest behind car using reg.exp?

/car black bla bla bla

so i can handle "car" and "black bla bla bla" seperately afterwards

TIA
/Lasse
 
Hi Lasse,

It would probably be

^(car)([^$]+)$

Note: I don't really remember which of $ and ^ actually stands for the
beginning of line and the end of line. So you may have to swap these
characters to obtain a valid RegExp. My legend is:

^ stands for the beginning of line
$ stands for the end of line

Hope this helps.
 
hmm not sure either, but "car" can be any length and not just "car"

it's more like:

/ followed by a Word, then a space, then Word(s)




Dmitriy Lapshin said:
Hi Lasse,

It would probably be

^(car)([^$]+)$

Note: I don't really remember which of $ and ^ actually stands for the
beginning of line and the end of line. So you may have to swap these
characters to obtain a valid RegExp. My legend is:

^ stands for the beginning of line
$ stands for the end of line

Hope this helps.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE


Lasse Edsvik said:
Hello

I was wondering how to match car and the rest behind car using reg.exp?

/car black bla bla bla

so i can handle "car" and "black bla bla bla" seperately afterwards

TIA
/Lasse
 
Then it would look like

^([a-zA-Z]+)\s(([a-zA-Z]+)|$)+

You might also like to use the ExplicitCapture option to have meaningful
pieces grouped. For example, the outer parenthes after \s are not a
meaningful capture by themselves, only the inner ones are.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Lasse Edsvik said:
hmm not sure either, but "car" can be any length and not just "car"

it's more like:

/ followed by a Word, then a space, then Word(s)




Dmitriy Lapshin said:
Hi Lasse,

It would probably be

^(car)([^$]+)$

Note: I don't really remember which of $ and ^ actually stands for the
beginning of line and the end of line. So you may have to swap these
characters to obtain a valid RegExp. My legend is:

^ stands for the beginning of line
$ stands for the end of line

Hope this helps.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE


Lasse Edsvik said:
Hello

I was wondering how to match car and the rest behind car using reg.exp?

/car black bla bla bla

so i can handle "car" and "black bla bla bla" seperately afterwards

TIA
/Lasse
 
Dmitriy,

hmm, but i pass that string and want to get out the 2 stringvalues for the
first Word and then second variable Word(s)

/Lasse


Dmitriy Lapshin said:
Then it would look like

^([a-zA-Z]+)\s(([a-zA-Z]+)|$)+

You might also like to use the ExplicitCapture option to have meaningful
pieces grouped. For example, the outer parenthes after \s are not a
meaningful capture by themselves, only the inner ones are.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Lasse Edsvik said:
hmm not sure either, but "car" can be any length and not just "car"

it's more like:

/ followed by a Word, then a space, then Word(s)




in message news:[email protected]...
Hi Lasse,

It would probably be

^(car)([^$]+)$

Note: I don't really remember which of $ and ^ actually stands for the
beginning of line and the end of line. So you may have to swap these
characters to obtain a valid RegExp. My legend is:

^ stands for the beginning of line
$ stands for the end of line

Hope this helps.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE


Hello

I was wondering how to match car and the rest behind car using reg.exp?

/car black bla bla bla

so i can handle "car" and "black bla bla bla" seperately afterwards

TIA
/Lasse
 
Back
Top