Solved

RegExp

Posted on 2004-03-29
3
352 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now