Re: Get regular expression



Mike wrote:
Xicheng Jia wrote:
Mike wrote:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in
matches. I would like to get what the actual regular expression is.
In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION
DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH
CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How
do I gain access to the expression (not the matches) at runtime?

you want to access the expression "HEART (CONDUCTION DEFECT)" or the
regex "^(.+)(?=\s*).*\1" at run-time?? dont think you can get exactly
the latter one though, for the previous one, you can use named capture,
like

^(?<expr>.+)(?=\s*).*\k<expr>

and access the variable "expr" at run time?

Xicheng

I want to access the expression "HEART (CONDUCTION DEFECT)" I'll try
your suggestion first off in the morning.


err, my bad. you need the match object's Groups property, like
Group("expr") or Group(1) to access the captured values..(Groups[...]
for C#)

Xicheng

.



Relevant Pages

  • Re: Get regular expression
    ... "HEART (CONDUCTION DEFECT)" is not an expression. ... The regular expression is the string ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Find repeating substring
    ... I need a regular expression to find repeating substrings (in ... the substring of interest would be "HEART (CONDUCTION ... HEART (CONDUCTION DEFECT) 37.33/2 HEART WITH ...
    (comp.lang.perl.misc)
  • Re: Get regular expression
    ... I would like to get what the actual regular expression is. ... DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH ... do I gain access to the expression at runtime? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Get regular expression
    ... I would like to get what the actual regular expression is. ... do I gain access to the expression at runtime? ... you want to access the expression "HEART (CONDUCTION DEFECT)" or the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Find repeating substring
    ... but let me play with this a bit to see if I can ... exclude that. ... HEART (CONDUCTION DEFECT) 37.33/2 HEART WITH ...
    (comp.lang.perl.misc)

Loading