Solved

RegExp

Posted on 2004-03-29
3
365 Views
Last Modified: 2010-04-05
Hi! may you know the  TRegExpr http://regexpstudio.com/) for Delhpi. So I have a large text file, that have some "UiD ( 12 )" pattern. I need to pick up the number from this string. I know that if I want to get the pattern I need to do a UiD \( [0-9]?. \) rexep search. And if I want to get the number from this pattern, I need to do a [0-9]?. . But can I join somehow this two regexp? I mean the first one give output pattern to the second one, so I get the number itself. pls help me!

0
Comment
Question by:Kosztik
  • 3
3 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
ID: 10709315
You should join them like this
"(UiD\(\ )([0-9]?.)(\ \))"
And in Match[1] You should have "UiD( "
in Match[2] - number
and in Match[3] " )"
0
 
LVL 17

Expert Comment

by:mokule
ID: 10709329
Here You've got example from usage articles provided with help to TRegExpr
Example 2
How to extract phone numbers from unformatted text (web-pages, e-mails, etc).
For example, we need only St-Petersburg (Russia) phones (city code 812).

procedure ExtractPhones (const AText : string; APhones : TStrings);
begin
  with TRegExpr.Create do try
     Expression := '(\+\d *)?(\((\d+)\) *)?(\d+(-\d*)*)';
     if Exec (AText) then
      REPEAT
        if Match [3] = '812'

         then APhones.Add (Match [4])
      UNTIL not ExecNext;
    finally Free;
   end;
end;

For the input text

"Hi !
Please call me at work (812)123-4567 or at home +7 (812) 12-345-67
truly yours .."

this procedure returns

APhones[0]='123-4567'

APhones[1]='12-345-67'

0
 
LVL 17

Expert Comment

by:mokule
ID: 10709355
It seems that I lost 1 space. Correct expression according to Your example should be
(UiD\ \(\ )([0-9]?.)(\ \))
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question