Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RegExp

Posted on 2004-03-29
3
Medium Priority
?
377 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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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 anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

824 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