End of line anchor $ match even there is extra trailing \n in matched string, so we use \Z instead of $
For example
^\w+$ will match the string abcd\n but ^\w+\Z is not
How about \A and when to use?
How would I extract the dollar amount from the following string
"some text will go here and more and more and then there will be some price $34.03 but that doesn't mean the string will end"
I want to extract $34.03...also want to extract if there is no cents
"some text will go here and more and more and then there will be some price $34 but that doesn't mean the string will end"
Here I want to extract $34
I not getting the desired effect from a script. I want the password to contain A-Z, a-z, 0-9, and special chars.
A-Z
a-z
0-9 2
special chars 2
string length = 8
So I want to force the user to use at least 2 digits and at least 2 special chars. Ok my script works but forces me to use the digits or chars back to back. I don't want that. e.g. password testABC55$$ is valid - but i don't want that.
Instead I want test$ABC5#8 to be valid. So basically the digits/special char can be the same or diff - but must be split up in the string.
PHP CODE:
$uppercase = preg_match('#[A-Z]#', $password);
$lowercase = preg_match('#[a-z]#', $password);
$number = preg_match('#[0-9]#', $password);
$special = preg_match('#[\W]{2,}#', $password);
$length = strlen($password) >= 8;
if(!$uppercase || !$lowercase || !$number || !$special || !$length) {
$errorpw = 'Bad Password';
Do you haven any useful example of the boundary matcher "\G"`? Please give me some real world examples. Java source is appreciated. From "Mastering regular expressions. Jeffrey E. F. Friedl" I got an useful example parsing HTML but I am not sure how if a translation to Java is possible.
I'm not familiar with Perl and boost regular expression and I want to convert a Perl code to c++.
I want to convert special regular expression in Perl into c++ using Boost regexp library.
Please help me understand what I must do?
Here is some regexps that a word of a sentence may match:
if ($word =~ /^[\.:\,()\'\`-]/) { # hack for punctuation
}
if ($word =~ /^[A-Z]/) {
return;
}
if ($word =~ /[A-Za-z0-9]+\-[A-Za-z0-9]+/) { # all hyphenated words
return;
}
if ($word =~ /.*[0-9].*/) { # all numbers
return;
}
Hi, if I have a input with new lines in it like:
[INFO]
xyz
[INFO]
How can I pull out the xyz part. I tried a pattern like /^\[INFO\]$(.*?)$\[INFO\]/ms, but perl gives me:
Use of uninitialized value $\ in regexp compilation at scripts\t.pl line 6.
I've been trying things to get interpolation to stop like using qr// but alas, no love.
In a url like the one below, I'd like to get the value of ProdId. The URL format will always be consistent, as will the parameter name, but the length of the value may change. It will always be numeric.
http://www.site.com/page.php?ProdId=2683322&xpage=2
Using PHP what's the fastest way to get it (I'll be processing 10,000's so speed is an issue) ?
Hi all;
Html Code:
<TD style="DISPLAY: none">999999999</TD>
<TD class=CLS1 >Name</TD>
<TD class=BLACA>271229</TD>
<TD>220</TD>
<TD>343,23</TD>
<TD>23,0</TD>
<TD>222,00</TD>
<TD>33222,8</TD>
<TD class=blacl>0</TD>
<TD class=black>0</TD>
<TD>3433</TD>
<TD>40</TD>
i need td in value how to make csharp, i wanna string array;
999999999
Name
271229
220
pls help
I have the following string:
<script>m('02:29:1467301/>Sender1*>some text message?<<02:29:13625N1/>Sender2*>Recipient2: another message??<>A<<02:29:1393100=>User1*|0User2*|%></B><<','');</script>
N.B. messages are separated by <<
I need extract from message the following parts:
1. Time
2. Sender
3. Recipient
4. Text
Recipient may being defined or not, this field is optional.
I do this by the following pattern:
(?<message>(?<time>\d{1,2}:\d{1,2}:[0-9a-z]+)/>(?<messageData>(?<sender>.+?)\*>(.+?)))<<
But, I cannot extract recipient separately from the message text.
(?<message>(?<time>\d{1,2}:\d{1,2}:[0-9a-z]+)/>(?<messageData>(?<sender>.+?)\*>(((?<recipient>.+?):){0,1}(?<messageText>.+?))))<<
Please help correct my pattern.
I need change background of all text that have two spaces from the start of the line.
text
shold be converted to "<div class='special'>text</div>"
That is easy:
$text = preg_replace("|^ (.+)|um", "<div class='special'>$1</div>", $text);
But
line1
line2
Is converted to
<div class='special'>line1</div>
<div class='special'>line2</div>
Though
<div class='special'>line1
line2</div>
is needed.
How that can be achieved?
I am currently writing a small texteditor. With this texteditor users are able to create small scripts for a very simple scripting engine.
For a better overview I want to highlight codeblocks with the same command like GoTo(x,y) or Draw(x,y).
To achieve this I want to use Regular Expresions (I am already using it to highlight other things like variables)
Here is my Expression (I know it's very ugly):
/(?<!GoTo|Draw|Example)(^(?:GoTo|Draw|Example)\(.+\)*?$)+(?!GoTo|Draw|Example)/gm
It matches the following:
lala
GoTo(5656) -> MATCH 1
sdsd
GoTo(sdsd) --comment -> MATCH 2
GoTo(23329); -> MATCH 3
Test()
GoTo(12) -> MATCH 4
LALA
Draw(23) -> MATCH 5
Draw(24) -> MATCH 6
Draw(25) -> MATCH 7
But what I want to achieve is, that the complete "blocks" of the same command are matched. In this case Match 2 & 4 and Match 5 & 6 & 7 should be one match. Tested with http://regex101.com/, the programming lanuage is vb.net.
Any advise would be very useful, Thanks in advance!
Hi,
I have so many println("") in my codes .. I know it is messy ... I want to put comment for each of the println("");
how to do that in VIM ? I mean I want to do that on multiple files.
Also if possible, can it detect whether the lines has // already or not ... if the lines has been commented .. I don't want to add new //
Hi,
I have a directory which contains several directories as follows:
/Music/
/Music/JoeBlogs-Back_In_Black-1980
/Music/JoeBlogs-Back_In_Black-(Remastered)-2003
/Music/JoeBlogs-Back_In_Black-(ReIssue)-1987
/Music/JoeBlogs-Thunder_Man-1947
I want a script to go through and tell me when there are 'possible' duplicates, in the example above it would pick up the following as possible duplicates from the directory list:
/Music/JoeBlogs-Back_In_Black-1980
/Music/JoeBlogs-Back_In_Black-(Remastered)-2003
/Music/JoeBlogs-Back_In_Black-(ReIssue)-1987
1) Is this possible?
2) If so please help!
I have a JavaScript variable which holds an HTML page and due to the setup I need to extract everything between <div id="LiveArea"> and </div> from that variable using JavaScript.
Any help is greatly appreciated.
Can anyone tell me how I could count the possible instances of a keyword in a block of text?
I've split a search term up into separate tokens, so just need to run through and do a count for every instance and removing punctuation or other special characters when making the count.
Secondly, if someone has inserted search terms surrounded by double quotes, i want to be able to skip explode, but just count instances of that exact phrase. It doesn't have to be case sensitive and I would like to remove punctuation from the phrase when doing the count.
Thirdly, in both cases i want to be able to ignore wordpress and html tags.
Lastly, if anyone know any good tutorials for relevant searches that answer the questions above, that would cool too.
I've got this far.
$results = $wpdb->get_results($sql);
$tokens = explode('search_terms');
// Re-arrange Relevant Results
foreach ($results As $forum_topic){
foreach($tokens As $token){
// count tokens in topic_title
if ($token ){
}
}
}
Here are the patterns:
Red,Green (and so on...)
Red (+5.00),Green (+6.00) (and so on...)
Red (+5.00,+10.00),Green (+6.00,+20.00) (and so on...)
Red (+5.00),Green (and so on...)
Each attribute ("Red,"Green") can have 0, 1, or 2 modifiers (shown as "+5.00,+10.00", etc.).
I need to capture each of the attributes and their modifiers as a single string (i.e. "Red (+5.00,+10.00)", "Green (+6.00,+20.00)".
Help?
hi,
similiar like this example, http://stackoverflow.com/questions/1336672/php-remove-brackets-contents-from-a-string i have no idea to replace
$str = '(ABC)some text'
into
$str = 'ABC';
currently use $str = preg_replace('/(.)/','',$str); but not works. how to fix this?
I am trying to find words starts with a specific character like:
Lorem ipsum #text Second lorem ipsum.
How #are You. It's ok. Done.
Something #else now.
I need to get all words starts with "#". so my expected results are #text, #are, #else
Any ideas?
I'm doing something in Java that requires input to be matched against the pattern ^[1-5]$. I should have a while loop looping through each line of input, checking it against the pattern, and outputting an error message if it does not.
Sudo code:
while (regex_match(/^[^1-5]$/,inputLine)) {
print ("Please enter a number between 1 and 5! ");
getNextInputLine(); }
I can use java.util.Scanner.hasMatch("^[^1-5]$"), but that will only match a single token, not the entire line. Any idea on how to make hasMatch match against the entire line? (Setting the delimiter to "\n" or "\0" doesn't work.)
I need to match and remove all tags using a regular expression in Perl. I have the following:
<\\??(?!p).+?>
But this still matches with the closing </p> tag. Any hint on how to match with the closing tag as well?
Note, this is being performed on xhtml.
I have strings of this type:
text (more text)
What I would like to do is to have a regular expression that extracts the "more text" segment of the string, so far I have been using this regular expression:
"^.*\\((.*)\\)$"
Which although it works on many cases, it seems to fail if I have something of the sort:
text (more text (even more text))
What I get is: even more text)
What I would like to get instead is:
more text (even more text) (basically the content of the outermost pair of brackets.)
Thanks
I'm trying to get to grips with regular expressions:
I have a database connection string and I'd like to use a regular expression to identify specific Keys and Values within it.
For example
server=foo;database=bar;uid=foo;pwd=bar
I'd like something to return "database=bar;" using the 'database' key to identify it, ideally it would be case insensitive. I can do this using normal code, but I think that this is exactly the sort of thing for which regular expressions were designed.
hi
segmentText = <input from textarea>;
testRgx = [/( \d+\.| [^\W\d_]\.|.)+?([!?.?](?= |$)|$)/g];
arrSegments = segmentText.match(testRgx);
This expression fails if segmentText has \n or other white spaces in it.I want to add
\n in to the list of chars that the above pattern use
[!?.?] = [!?.?\n] so that the segment is separated based on the \n character
I'm using preg_* in PHP to search for the pattern <!-- %{data=THIS GETS MATCHED}% --> and pull out the matched text.
The pattern for this is:
preg_match('#<!-- %{' . $knownString . '\s*=\s*(.*?)}% -->#', ...)
What I would like it to do is search across multiple lines for the string. For example:
<!-- %{data=
THIS GETS
MATCHED AND
RETURNED
}% -->
How can I edit my current pattern to have this search ability?