RegExp question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting RegExp question
# 1  
Old 06-28-2005
RegExp question

Hi guys,

does anyone know how to test for a regular expression - i want to include it in a script to make sure the variable is a regexp

cheers
# 2  
Old 06-28-2005
There is no such way, everything could be a regular expression.

If there is a string "file" it could be a regexp too - one that matches the word "file" and nothing else.

bakunin
# 3  
Old 06-28-2005
You could check for whether a variable is a valid regular expression.

Code:
check_re_valid() {
    grep -- "$1" < /dev/null 2>/dev/null
    if [ $? -eq 2 ]; then
        return 1
    else
        return 0
}

# 4  
Old 06-28-2005
penfold,

Read the rules.

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.

Thanks !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

A Regexp You Can Use Everywhere

¯\_(ツ)_/¯ bakunin (0 Replies)
Discussion started by: bakunin
0 Replies

2. Shell Programming and Scripting

Regexp

I would like to extract "1333 Fairlane" given the below text. The word "Building:" is always present. The wording between Building and the beginning of the address can be almost anything. It appears the the hyphen is there most of the time. Campus: Fairlane Business Park Building:... (9 Replies)
Discussion started by: bbaker@copesan.
9 Replies

3. Shell Programming and Scripting

Question on regexp in TCL

I need some help with regexp in tcl. The following code does work if the $urlvar ends in jpg,jpeg,png or gif. Eg, protocol(http/https)://testsite.com/images/image1.jpg if { ! } { //Do something } My problem is that if the URL does not end in these extensions this regexp is of no... (1 Reply)
Discussion started by: ampak
1 Replies

4. Shell Programming and Scripting

Question on TCL regexp and match

Hello everyone, I'm new in tcl scripting. I'm currently studying a tcl script and came across this line: regexp {(\d+)(\S?)} $opts match opt swi According to my understanding, this line means to search in the opts variable for one or more digit, followed by a non-whitespace character... (2 Replies)
Discussion started by: mar85
2 Replies

5. Shell Programming and Scripting

help with grep regexp

My input file looks like this: 13154|X,the deer hunter 13154|Y,the good life 1316|,american idol 1316|,bowling 1316|,chuck etc... The X, Y, or any other character (besides a comma) after the pipe is a "Device Type". I want to strip out lines that do not have a device type. I have... (2 Replies)
Discussion started by: jwinsk
2 Replies

6. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

7. Shell Programming and Scripting

Help with regexp

Hi there! I would like to know how to find and replace all numbers in a *.html file and make them bold. Any help will be appreciated! :) (7 Replies)
Discussion started by: agasamapetilon
7 Replies

8. Shell Programming and Scripting

regexp help

I'd like to know if there is a catchall line for renaming the following patterns: s01e03 -> 01x03 s4e9 -> 04x09 s10e08 ->10x08 and possibly even: 318 -> 03x18 1002 ->10x02 if its the first 3 or first digit number in the string. thanks! (0 Replies)
Discussion started by: TinCanFury
0 Replies

9. UNIX for Advanced & Expert Users

regexp

Hi guys, does anyone know how to test for a regular expression - i want to include it in a script to make sure the variable is a regexp cheers (1 Reply)
Discussion started by: penfold
1 Replies

10. UNIX for Dummies Questions & Answers

vi + regexp + substitute

Another enigma (for me) Using VI I edit some files in which I want to erase many lines I don't need anymore usually I do something like that::%s/line_to_suppress//g and it is doing fine but in this case, the pattern to erase contains some special characters so I do it like... (9 Replies)
Discussion started by: Lomic
9 Replies
Login or Register to Ask a Question