Help with regular expression

S

sondar

Can anyone help me please?

I have a regular expression "^A .* B$"

If this matches against "A B A B" then how can I tell that ".*" was
matched against "B A"?

Thanks,
Campbell
 
A

Alexander Mueller

Can anyone help me please?

I have a regular expression "^A .* B$"

If this matches against "A B A B" then how can I tell that ".*" was
matched against "B A"?

Thanks,
Campbell

I am not familar to RegExp in .Net
In VBScript and JavaScript you'd define a submatch by
simply using paranthesis:

'VBScript
rx.Pattern = "^A( .* )B$"

and return the part inbetween by accessing the submatch.
There are multiple ways to do this, one is

'VBScript
sm = rx.replace("A B A B", "$1")



I know dotnet uses a different term then 'submatch'.
(i think they call it backreference instead ... not sure)
and a different method for retrieving it, but the basic mechanism
and the pattern are the same.

MfG,
Alex
 
E

eBob.com

I am certainly not a regex expert, but I think that what you need to search
for is "capture".

Good Luck, Bob
 
S

sondar

Thank you both, that was the push I needed. I needed to use named
groups, i.e. change the pattern to

"^A(?<mymatch>.*)B$"

I can then use the re.Match().Groups collection to return the value of
the mymatch group which in the case above would be "B A".

Cheers,
Campbell
 

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

Top