Replace what you want with something easily matchable, delete what you don't want, and restore it. This avoids needing strange convolution, backreferences, or non-greedy matching.
Another method would be splitting on RR45, changing all non-blank tokens into "%", then imploding again.
Hello,
from the gnu sed manual, I should be able to do this:
`\(REGEXP\)'
Groups the inner REGEXP as a whole, this is used to:
* Apply postfix operators, like `\(abcd\)*': this will search
for zero or more whole sequences of `abcd', while `abcd*'
... (3 Replies)
Hi there, I need to test that a variable ($VAR) matches a regex mask in BASH. I have the exact thing working in perl (below), but could somebody advise me how i would do the same in BASH ? do i need to use something like egrep ?
#!/bin/perl -w
my $VAR = "some value";
if ( $VAR =~... (4 Replies)
Why is only hello3 being printed? There must be some kind of syntax problem because the file list definitely includes all the file extensions line by line.
#!/bin/bash
find '/home/myuser/folder/' -name '*.c' -type f | while read F
do
if ] # if the file name ends in .txt.c
then
... (6 Replies)
I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly:
if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Hi,
I'm trying to validate if a string matches a regular expression, but it is not working. Am I missing something? Do I need to scape any of the characters?
if echo 'en-GB' | egrep '({1,8})(-{1,8})*' >/dev/null; then
echo Valid value
fi
Thanks in advance (6 Replies)
Hi ,
I am trying to extract contents of a file between specified time stamp. but it does not seem to work. i am trying to extract output of /var/adm/messages between 15:00:00 to 15:23:59 .
i have tried two regex the first one seems to kind of work. it displays some output. the second one is... (13 Replies)
I have a number of files that I pass through awk/gsub.
I believe to have found a working regex and on 'test bed' sites it matches, however within gsub it does not.
Examples:
Initial data:
/Volumes/Daniel/Public/Drop Box/_Hellsing_Ultimate_OVA_-_10_.mkv
gsub & regex:
gsub("\]+\]",""
... (4 Replies)
I am not a big expert in regex and have just little understanding of that language.
Could you help me to understand the regular Perl expression:
^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{
------
This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Perl::Critic::Policy::RegularExpressions::ProhibitCompleUsereContributed Perl DPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes(3)NAME
Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes - Split long regexps into smaller "qr//" chunks.
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
Big regexps are hard to read, perhaps even the hardest part of Perl. A good practice to write digestible chunks of regexp and put them
together. This policy flags any regexp that is longer than "N" characters, where "N" is a configurable value that defaults to 60. If the
regexp uses the "x" flag, then the length is computed after parsing out any comments or whitespace.
Unfortunately the use of descriptive (and therefore longish) variable names can cause regexps to be in violation of this policy, so
interpolated variables are counted as 4 characters no matter how long their names actually are.
CASE STUDY
As an example, look at the regexp used to match email addresses in Email::Valid::Loose (tweaked lightly to wrap for POD)
(?x-ism:(?:[^( 40)<>@,;:".\[] 00- 37x80-xff]+(?![^( 40)<>@,;:".\[]
00- 37x80-xff])|"[^\x80-xff
15"]*(?:\[^x80-xff][^\x80-xff
15
"]*)*")(?:(?:[^( 40)<>@,;:".\[] 00- 37x80-xff]+(?![^( 40)<>@,;:".\[
] 00- 37x80-xff])|"[^\x80-xff
15"]*(?:\[^x80-xff][^\x80-xff
15"]*)*")|.)*@(?:[^( 40)<>@,;:".\[] 00- 37x80-xff]+(?![^( 40)<>@,
;:".\[] 00- 37x80-xff])|[(?:[^\x80-xff
15[]]|\[^x80-xff])*]
)(?:.(?:[^( 40)<>@,;:".\[] 00- 37x80-xff]+(?![^( 40)<>@,;:".\[] 00
- 37x80-xff])|[(?:[^\x80-xff
15[]]|\[^x80-xff])*]))*)
which is constructed from the following code:
my $esc = '\\';
my $period = '.';
my $space = '