Solved

RegExp

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

808 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