regexp: match string that contains list of chars


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers regexp: match string that contains list of chars
# 8  
Old 10-14-2010
Quote:
Originally Posted by jimcanoa
that it can be done with regexps! I mean, if you can test if a number is a primer number with regular expressions, I refuse to believe this simple thing can't be done Smilie
Of course it can be done with regex, you wrote it in the first post. The question is can it be done simpler? I think not.
# 9  
Old 10-14-2010
Your definition of one regex is a bit arbitrary, as I think some things are not included in base regex, like egrep multi-pattern matching using () and |, where an outer super-regex call may be doing many simple-regex calls. A bad regex can really slow things, too, so sometimes three simple is much better than one ugly. Academic problems are fun, but real world solutions are worth dollars.
# 10  
Old 10-16-2010
#deleted#

---------- Post updated at 02:20 AM ---------- Previous update was at 02:16 AM ----------

Ruby
Code:
>> s = "cxxbxxc"
=> "cxxbxxc"
>> s["a"] and s["b"] and s["c"] and print "ok"
=> nil
>> s = "cxxbxxa"
=> "cxxbxxa"
>> s["a"] and s["b"] and s["c"] and print "ok"
ok=> nil
>> s = "axxbxxa"
=> "axxbxxa"
>> s["a"] and s["b"] and s["c"] and print "ok"
=> nil

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

sed - print only the chars that match a given set in a string

For a given string that may contain any ASCII chars, i.e. that matches .*, find and print only the chars that are in a given subset. The string could also have numbers, uppercase, special chars such as ~!@#$%^&*(){}\", whatever a user could type in without going esoteric For simplicity take... (1 Reply)
Discussion started by: naderra
1 Replies

3. Shell Programming and Scripting

sed to remove newline chars based on pattern mis-match

Greetings Experts, I am in AIX; I have a file generated through awk after processing the input files. Now I need to replace or remove the new-line characters on all lines that doesn't have a ; which is the last character on the line. I tried to use sed 's/\n/ /g' After checking through the... (6 Replies)
Discussion started by: chill3chee
6 Replies

4. Shell Programming and Scripting

Add an string at every x chars

Hi All, I have a file fo around 15k bytes which i need to insert a string " + "at every 250 bytes. I found some ideas here using perl to split into lines and tried to addapt it but the results where not satisfactory for instance i tried to change #!/usr/bin/perl $teststring =... (9 Replies)
Discussion started by: kadu
9 Replies

5. Shell Programming and Scripting

Regexp for string that might contain a given character

I'm probably just not thinking of the correct term to search for :-) But I want to match a pattern that might be 'ABC' or '1ABC' there might be three characters, or there might be four, but if there are four, the first has to be 1 (1 Reply)
Discussion started by: jnojr
1 Replies

6. 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

7. Shell Programming and Scripting

extract string until regexp from backside

Hi, I searched in the forums, but I didn't find a good solution. My problem is: I have a string like "TEST.ABC201005.MONTHLY.D101010203". I just want to have the string until the D100430, so that the string should look like: "TEST.ABC201005.MONTHLY.D" The last characters after the D can be... (8 Replies)
Discussion started by: elifchen
8 Replies

8. Shell Programming and Scripting

perl regexp: no match across newlines

Hi. Here's a tricky one (at least to me): I have a file named theFile.txt (UTF-8) that contains the following: a b cWhen I execute perl -pe 's|a.*c|d|sg' theFile.txtin bash 3.2 on MAC OS X 10.6, I get no match, i.e. the result is a b cagain. Any clues why? (2 Replies)
Discussion started by: BatManWSL
2 Replies

9. Shell Programming and Scripting

regexp to get first line of string

Hi everybody for file in * #Bash performs filename expansion #+ on expressions that globbing recognizes. do output="`grep -n "$1" "$file"`" echo "$file: `expr "$output" : '\(^.*$\)'`" done In the above bash script segment, I try to print just the first line of string named... (3 Replies)
Discussion started by: jonas.gabriel
3 Replies

10. Shell Programming and Scripting

RegExp negative match not working

or I don't know how to make it work ... Hello im trying to build regexp that will match me single string or function call inside of brackets for example I have : <% myFunction("blah",foo) %> or <% myVar %> and not match : <% if(myFunction("blah",foo)==1) %> or <% while(myvar < 3){... (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question