Regexp to match all characters including "?"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regexp to match all characters including "?"
# 1  
Old 12-14-2009
Regexp to match all characters including "?"

Hi everyone,

I'm almost tearing my hairs to find a valid regexp which will match EVERY character in a string, including the question mark!

Specifically I need to match a string which contains the word (example) "stringtobematched" at the end of it.

Everyone would suggest this:

^(.*)stringtobematched$

This obviously works, but it stops working if I introduce the question mark (?) character at any point before the matching pattern.

For example:

blablabla?blastringtobematched

..will not be matched!

It looks like that the "." (dot) character doesn't match the question mark.

Is there a regexp which matches every characters question marks included? (not necessarily matching only strings with question marks, but optionally)

I've tried something like this:

(.*)[\?](.*)blastringtobematched?

But it didn't work Smilie

Any help?


Thanks!


PS: regexp being used from Apache's mod_rewrite. Writing in this forum because after all regexp's are still considered part of shell scripting. Apologies in case I was wrong!

Last edited by lycaon; 12-14-2009 at 12:23 PM..
# 2  
Old 12-14-2009
Hello,

The first pattern would be matched by:
Code:
.*stringtobematched$

And also the questionmark:

Code:
$ echo 'blablabla?blastringtobematched'|grep '.*stringtobematched$'
blablabla?blastringtobematched

And this should specifically match a string with a question mark.
Code:
.*?.*blastringtobematched

E.g:
Code:
$ echo 'blablabla?blastringtobematched'|grep '.*?.*blastringtobematched'
blablabla?blastringtobematched


Last edited by Scrutinizer; 12-14-2009 at 12:35 PM..
# 3  
Old 12-14-2009
mod_rewrite doesn't seem to match it. I've also tried to escape it e.g. \? but still it doesn't get matched Smilie
# 4  
Old 12-14-2009
Code:
^.*stringtobematched.*$

And what happens with this ?
# 5  
Old 12-14-2009
Perhaps ? doesn not get interpreted as part of URL but as the start of the parameter string?
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search file containing ps results for a match "my.cnf" and then for a second match . "ok:" and

I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for: my.cnf /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Advanced & Expert Users

AIX - io info get from "libperfstat" not match "iostat"

Hi, everyone. I need to write a program to get io info based on libperfstat. But the "write time" of a disk is just half of the value get from iostat. I'm confused and can't explain. Help please. How I calculate "write service time per sec": In iostat: write service... (0 Replies)
Discussion started by: jackliang
0 Replies

5. Shell Programming and Scripting

Regexp to separated rows by "asterisks-new line" in awk

Hello to all, I have the text file below, how would be the REGEXP to set the RS to separate registers by asterisks-newline-asterisks (highlighted in red) and FS as the default, in order that the fourth field ($4) always be the number after REG (in blue)? I'm trying with code below, but is... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

6. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies
Login or Register to Ask a Question