Re: Problem with repeating characters in regex
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Thu, 27 Sep 2007 20:17:39 +0100
Mike Martin wrote:
On 27/09/2007, Rob Dixon <rob.dixon@xxxxxxx> wrote:nope - I am trying to find only strings that start with ! and not
Mike Martin wrote:Hi Mike. I'm confused as to what you're trying to do, as your regex
Hi I am trying to capture only the first occurence of a charcter
followed by any word ie: in this sample text
!this is a first level heading
!!this is a 2nd level heading
I only want to find the first item and not the second
current code
$line=~s/\!(^\![A-Z][a-z].+)/$1/gc;
it either doesnt capture any ! or takes out the first ! when there is a double
any ideas
doesn't make sense and is a subtitution rather than a pattern match. My
best guess is that you want to elevate all second-level headings to first-
level ones? Maybe something like
$line =~ s/^!(![a-z].+)/$1/gi;
does what you need.
those starting with !!
Then you want
$line =~ s/^!([a-z].+)/$1/i;
or, better:
$line =~ s/^!(?=[^!])//;
Rob
.
- References:
- Problem with repeating characters in regex
- From: Mike Martin
- Re: Problem with repeating characters in regex
- From: Rob Dixon
- Problem with repeating characters in regex
- Prev by Date: Re: $File::Find and no_chdir
- Next by Date: Installing perl-5.8.8
- Previous by thread: Re: Problem with repeating characters in regex
- Next by thread: How to set environment variable
- Index(es):