LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2011, 03:09 AM   #16
915086731
Member
 
Registered: Apr 2010
Posts: 144

Original Poster
Blog Entries: 6

Rep: Reputation: 2

Thanks all!

Last edited by 915086731; 09-01-2011 at 03:16 AM.
 
Old 09-01-2011, 03:11 AM   #17
915086731
Member
 
Registered: Apr 2010
Posts: 144

Original Poster
Blog Entries: 6

Rep: Reputation: 2
Thanks all!
The following works ok in bash shell:
Code:
[river@localhost ~]$ [[ "123" =~ [[:digit:]]{3} ]] && echo "ok" || echo "error"
ok
[river@localhost ~]$ [[ "123" =~ [0-9]{3} ]] && echo "ok" || echo "error"
ok
The following is what I want:
Code:
[river@localhost ~]$ reg='\b[0-9]{3}\b'
[river@localhost ~]$ [[ "123" =~ $reg ]] && echo "ok" || echo "error"
ok
However, why I must put the expression in a variable .
Code:
[river@localhost ~]$ [[ "123" =~ \b[0-9]{3}\b ]] && echo "ok" || echo "error"
error
 
Old 09-01-2011, 03:56 AM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
However, why I must put the expression in a variable .
Did you read my post #14?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression to Grep for a n digit number somupl86 Linux - General 7 11-24-2010 06:11 AM
Substitue single-digit, two-digit, and 3-digit numbers with text using sed dmason165 Programming 13 08-07-2009 10:38 AM
Regular Expression harkonen Programming 6 07-12-2008 12:06 PM
regular expression (.*?) uttam_h Programming 6 05-30-2008 05:45 PM
Regular Expression slizadel Programming 4 07-28-2003 05:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration