perl regular expression not inbetween issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl regular expression not inbetween issue
# 1  
Old 09-18-2012
perl regular expression not inbetween issue

Dear All,

Code:
perl -e 'if($ARGV[0] =~ /\A^[0-9]{10}\z/){print "Valid string\n"}else{print "Invalid string\n"}' '1234567899'
Valid string

perl -e 'if($ARGV[0] =~ /\A^[0-9]{8}\z/){print "Valid string\n"}else{print "Invalid string\n"}' '12345678'
Valid string

individually both works, anyway to combine both together? the outcome should be "Valid string" when the length eq 8 or 10, but not 9, so i cannot use {8,10} as it includes 9.

Thanks
# 2  
Old 09-18-2012
Code:
 
perl -e 'if($ARGV[0] =~ /\A^[0-9]{8}\z/ || $ARGV[0] =~ /\A^[0-9]{10}\z/){print "Valid string\n"}else{print "Invalid string\n"}' '1234567890'

# 3  
Old 09-18-2012
Code:
perl -e 'if($ARGV[0] =~ /\A^([0-9]{8}|[0-9]{10})\z/){print "Valid string\n"}else{print "Invalid string\n"}' '1234567899'

Here you go...
# 4  
Old 09-18-2012
Thanks, got both your points.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

2. Shell Programming and Scripting

Perl regular expression help!

Hi I am doing something basic like... if ($stringvariable =~ /have not typed/) I have a little problem because the 'not' in the expression gets highlighted as a kind of a '!'..what am I supposed to do in this situation? Thank you ---------- Post updated at 03:24 PM ----------... (1 Reply)
Discussion started by: vas28r13
1 Replies

3. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

4. Shell Programming and Scripting

Perl regular expression and %

Could you help me with this please. This regular expression seems to match for the wrong input #!/usr/bin/perl my $inputtext = "W1a$%XXX"; if($inputtext =~ m/+X+/) { print "matches\n"; } The problem seems to be %. if inputtext is W1a$XXX, the regex doesnot match.... (5 Replies)
Discussion started by: suppandi7
5 Replies

5. Shell Programming and Scripting

Perl Regular Expression

Hello, I am trying to use perl LWP module to read and get a specfic URL page. The issue is that the URL ends with the data and time and time is not consistent it changes all the time. if anyone could help me how to write a regular expressin that would work in the LWP::UserAgent get function to... (0 Replies)
Discussion started by: bataf
0 Replies

6. Shell Programming and Scripting

Need perl regular expression

Hi, I am looking for a Perl regular expression to match the below pattern of a java script file. var so = object.device.load('camera','value'); I want to grep out such lines present in the *.js files. The conditions are: a) the line may start with blank space(s) b) always the... (3 Replies)
Discussion started by: royalibrahim
3 Replies

7. Shell Programming and Scripting

Regular expression in Perl

Hi, I need and expression for a word like abc_xyz_ykklm The expresion should indicate that the word starts with abc and end with ykklm but does not contain xyz string in the middle. Example: abc_tmn_ykklm is ok and abc_xyz_ykklm is not Ok. Please help. Regards. (1 Reply)
Discussion started by: asth
1 Replies

8. Shell Programming and Scripting

perl regular expression

Dear all, I have a simple issue on a perl regular expression. I want to get the characters in red from the next lines : POWER_key LEFT_key RIGHT_key OK_key DOWN_key and so on... Thanks in advance for reply. Ludo (1 Reply)
Discussion started by: lsaas
1 Replies

9. Shell Programming and Scripting

PERL regular expression

Hello all, I need to match the red expressions in the following lines : MACRO_P+P-_scrambledServices_REM_PRC30.xml MACRO_P+P-_scrambledServices_REM_RS636.xml MACRO_P+P-_scrambledServices_REM_RS535.xml and so on... Can anyone give me a PERL regular expression to match those characters ? ... (5 Replies)
Discussion started by: lsaas
5 Replies

10. Shell Programming and Scripting

Regular expression issue

Hi, I have the following string: $string= BG_1_12345_?_XX.SVF The '?' means that any character could be in that position. If from a file i will read the string $str=12345 how can i modify the $str in order to be $str=$string. Best regards, Christos (4 Replies)
Discussion started by: chriss_58
4 Replies
Login or Register to Ask a Question