I'm having trouble writing a regular expression that matches the text I need it to. Let me give an example to express my trouble. Suppose I have the following text:
I want to find the line "find me" and match everything up from it to the nearest "else if(condition)". There can be anything at all between them, including newline characters. I tried the following regular expression:
Unfortunately the above regular expression does not do what I want. It finds the first "else if(condition)" and selects everything down to the first "find me" despite the nongreedy asterisk. Is there a way to match the "find me" first and then search up for for the "else if(condition)"?
Note: I know the above example doesn't make any sense code-wise. It's not the text I'm trying to match, but it's much less complicated and expresses what I'm trying to accomplish better.
How can i create a regular expression which can detect a new line charcter followed by a special character say * and replace these both by a string of zero length?
Eg:
Input File san.txt
hello
hi ... (6 Replies)
I have following content in the file
CancelPolicyMultiLingual3=U|PC3|EN
RestaurantInfoCode1=U|restID1|1
.....
I am trying to use following matching extression
\|(+)
to get this
PC3|EN
restID1|1
Obviously it does not work.
Any ideas? (13 Replies)
how to find for a file whose name has all characters in uppercase after 'project'?
I tried this:
find . -name 'project**.pdf'
./projectABC.pdf
./projectABC123.pdf
I want only ./projectABC.pdf
What is the regular expression that correponds to "all characters are capital"?
thanks (8 Replies)
Hi,
below is a piece of code written by my predecessor at work.
I'm kind of a newbie and am trying to figure out all the regular expressions in this piece of code.
It is really a tough time for me to figure out all the regular expressions.
Please shed some light on the regular expressions... (3 Replies)
Hi,
In ksh, I am trying to compare folder names having -141- in it's name.
e.g.: 4567-141-8098 should match this expression '*-141-*'
but, -141-2354 should fail when compared with '*-141-*'
simlarly, abc should fail when compared with '*-141-*'
I tried multiple things but nevertheless,... (5 Replies)
I have a flat file with the following drug names
Nutropin AQ 20mg PEN Cart 2ml
Norditropin Cart 15mg/1.5ml
I have to extract digits that are before mg i.e 20 and 15 ; how to do this using regular expressions
Thanks
ram (1 Reply)
hi everybody
I am a new user to this forum and its previous posts have been very useful. I'm searching in a file using grep for patterns like
12.13.444
55.44.443
i.e. of form
<digit><digit>.<digit><digit>.<digit><digit><digit>
Can anybody help me with this.
Thanks in advance (4 Replies)
I have a file that I'm trying to find all the cases of phone number extensions and deleting them. So input file looks like:
abc
x93825
def
13234
x52673
hello
output looks like:
abc
def
13234
hello
Basically delete lines that have 5 numbers following "x". I tried: x\(4) but it... (7 Replies)
I need to pick a part of string lets stay started with specific character and end with specific character to replace using sed command
the line is like this:my audio book 71-skhdfon1dufgjhgf8.wav'
I want to move the characters beginning with - end before.
I have different files with random... (2 Replies)
Discussion started by: XP_2600
2 Replies
LEARN ABOUT PHP
mb_ereg_replace
MB_EREG_REPLACE(3) 1 MB_EREG_REPLACE(3)mb_ereg_replace - Replace regular expression with multibyte supportSYNOPSIS
string mb_ereg_replace (string $pattern, string $replacement, string $string, [string $option = "msr"])
DESCRIPTION
Scans $string for matches to $pattern, then replaces the matched text with $replacement
PARAMETERS
o $pattern
- The regular expression pattern. Multibyte characters may be used in $pattern.
o $replacement
- The replacement text.
o $string
- The string being checked.
o $option
- Matching condition can be set by $option parameter. If i is specified for this parameter, the case will be ignored. If x is
specified, white space will be ignored. If m is specified, match will be executed in multiline mode and line break will be
included in '.'. If p is specified, match will be executed in POSIX mode, line break will be considered as normal character. If e
is specified, $replacement string will be evaluated as PHP expression.
RETURN VALUES
The resultant string on success, or FALSE on error.
NOTES
Note
The internal encoding or the character encoding specified by mb_regex_encoding(3) will be used as the character encoding for this
function.
Warning
Never use the e modifier when working on untrusted input. No automatic escaping will happen (as known from preg_replace(3)). Not
taking care of this will most likely create remote code execution vulnerabilities in your application.
SEE ALSO mb_regex_encoding(3), mb_eregi_replace(3).
PHP Documentation Group MB_EREG_REPLACE(3)