Home > Archive > PERL Beginners > January 2006 > Simple RegEx expresion
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Simple RegEx expresion
|
|
| George Homorozeanu 2006-01-25, 7:55 am |
| Hi,
I am very new in RegEx and I want to be able to write an expresion that does
the following:
Return all the characters from a string starting from the 5-th character.
Given:
Linz_Untauglich Dr.
Result:
Untauglich Dr.
Thanks,
George.
| |
| Paul Lalli 2006-01-25, 7:55 am |
| George Homorozeanu wrote:
> I am very new in RegEx and I want to be able to write an expresion that does
> the following:
>
> Return all the characters from a string starting from the 5-th character.
>
> Given:
> Linz_Untauglich Dr.
>
> Result:
> Untauglich Dr.
Why are you insisting on regular expression for this problem. That is
the "wrong" (ie, not most efficient or clear) solution. The "correct"
solution is substr(). This is what this function is designed for.
my $string = 'Linz_Untauglich Dr.';
print substr($string, 5), "\n";
If you really *wanted* a regular expression for some unknown reason...
my $string = 'Linz_Untauglich Dr.';
if ($string =~ /^.{5}(.*)/){
print "$1\n";
}
But I have no idea why you'd want that instead of substr().
perldoc -f substr
Paul Lalli
| |
| Xavier Noria 2006-01-25, 7:55 am |
| On Jan 25, 2006, at 12:23, George Homorozeanu wrote:
> I am very new in RegEx and I want to be able to write an expresion
> that does
> the following:
>
> Return all the characters from a string starting from the 5-th
> character.
You want to do it with a regexp for some particular reason? That's
the job of substr().
-- fxn
| |
| Randal L. Schwartz 2006-01-25, 6:57 pm |
| >>>>> "George" == "George Homorozeanu" <george_homorozeanu@hotmail.com> writes:
George> Hi,
George> I am very new in RegEx and I want to be able to write an expresion that does
George> the following:
George> Return all the characters from a string starting from the 5-th character.
Call me paranoid, but this is phrased in a way that it sounds like
an assignment, aka Homework Question.
Give us the real context for this.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
| |
| George Homorozeanu 2006-01-25, 6:57 pm |
| I need it with RegEx, that's my problem.
Thanks,
George.
"Xavier Noria" <fxn@hashref.com> schrieb im Newsbeitrag
news:5CA236A3-991F-4A08-9390-E2DB95DB9FE9@hashref.com...
> On Jan 25, 2006, at 12:23, George Homorozeanu wrote:
>
>
> You want to do it with a regexp for some particular reason? That's the
> job of substr().
>
> -- fxn
>
| |
| Dmitry 2006-01-25, 6:57 pm |
| Hello George,
Wednesday, January 25, 2006, 1:23:41 PM, you wrote:
GH> Hi,
GH> I am very new in RegEx and I want to be able to write an expresion that does
GH> the following:
GH> Return all the characters from a string starting from the 5-th character.
GH> Given:
GH> Linz_Untauglich Dr.
GH> Result:
GH> Untauglich Dr.
GH> Thanks,
GH> George.
Please, use this example:
---start---
$str = "Linz_Untauglich Dr.";
$str =~ s/^.{5}//;
print "$str";
---finish---
Result: text "Untauglich Dr." is printed
--
Best regards,
Dmitry Motevich mailto:rst@tut.by
Address: Minsk/Belarus
| |
| John Doe 2006-01-25, 6:57 pm |
| George Homorozeanu am Mittwoch, 25. Januar 2006 16.12:[color=darkred]
> I need it with RegEx, that's my problem.
>
> Thanks,
>
> George.
>
> "Xavier Noria" <fxn@hashref.com> schrieb im Newsbeitrag
> news:5CA236A3-991F-4A08-9390-E2DB95DB9FE9@hashref.com...
>
Could you have a look at the following man page (type it at the cmdline):
perldoc perlretut
This is a (short) tutorial about regexes. Although this list is for beginners,
I personally feel that it is advisable to have a minimal understanding about
the code one writes - and your regex question is *very* basic and described
in the man pages.
You say that you want to be *able* to *write* this expression, so I don't
think my post is impolite.
If, after reading the manual and having *tried* to write the regex, you still
need help, post again.
(The full regex details you can find with
perldoc perlre)
hth, joe
| |
| Mazhar 2006-01-26, 6:57 pm |
| Hi George,
Are you looking for a TCL script or a PERL regex expression, if you are
using PERL
then try the code what Dmitry Motevich has written if u need in TCL then
try the below
-----------------------------------------------------------
set x "Linz_Untauglich Dr."
set result [regexp (_)(.*) $x match];
puts $match;
------------------------------------------------------------
Regards
Mazhar
On 1/25/06, John Doe <security.department@tele2.ch> wrote:
>
> George Homorozeanu am Mittwoch, 25. Januar 2006 16.12:
> expresion that
> That's the
>
> Could you have a look at the following man page (type it at the cmdline):
>
> perldoc perlretut
>
> This is a (short) tutorial about regexes. Although this list is for
> beginners,
> I personally feel that it is advisable to have a minimal understanding
> about
> the code one writes - and your regex question is *very* basic and
> described
> in the man pages.
>
> You say that you want to be *able* to *write* this expression, so I don't
> think my post is impolite.
>
> If, after reading the manual and having *tried* to write the regex, you
> still
> need help, post again.
>
> (The full regex details you can find with
> perldoc perlre)
>
> hth, joe
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
| |
| Paul Lalli 2006-01-26, 6:57 pm |
| Mazhar wrote:
> Are you looking for a TCL script or a PERL regex expression,
The OP posted to a Perl Beginners group/list. Where the hell did TCL
come into the conversation?
By the way, it's Perl, not PERL.
perldoc -q difference
Paul Lalli
|
|
|
|
|