This is more of a generic regex question than a PHP-specific one.
I am given different strings that may look like:
A/B/PA ID U/C/D
And I'm trying to extract the segment in the middle slashes that has spaces ("/PA ID U") using:
preg_match('/(\/PA .+)(\/.+|$)/', '', $matches);
However, instead of getting "/PA ID U" as I was ex...
I have a string (e.g. "AABBCCDDEEFF") and want to split this into an array with each element containing two characters - ["AA", "BB", "CC", "DD", "EE", "FF"].
...
I have an HtmlTextArea and I want to restrict the number of characters users can input to 500.
Currently I've used a RegularExpressionValidator...
RegularExpressiondValidator val = new RegularExpressiondValidator ();
val.ValidationExpression = "^.{0,500}$";
val.ControlToValidate = id;
val.ErrorMessage = "blah";
... this is fine when ...
Hey,
I got a question regarding regexp in general. I'm currently building a register form where you can enter the full name (given name and family name) however I cant use [a-zA-Z] as a validation check because that would exclude everyone with a "foreign" character.
What is the best way to make sure that they don't enter a symbol, in bo...
I want to validate a string which can be an email or multiple emails separated by commas.
For example:
[email protected] -> TRUE
bill -> FALSE
[email protected],[email protected]" -> TRUE
[email protected],[email protected], bob" -> false
bob,[email protected],[email protected]" -> false
I came ou...
Recently, somewhere on the web*, I found a reference for regular expressions which described a "third way" of greediness, different both
from greedy (.*) and lazy (.*?) matching.
I've now tried searching SO, Googling, and even searching my browser history, but to no avail.
Can anyone make a good guess at what it was I saw?
Clarific...
If I have a file containing some escaped parens, how can I replace all instances with an unescaped paren using Perl?
i.e. turn this:
.... foo\(bar ....
into this
.... foo(bar ....
I tried the following but receivied this error message:
perl -pe "s/\\\(/\(/g" ./file
Unmatched ( in regex; marked by <-- HERE in m/\\( <-- HERE / at ...
I'm looking at a string and trying to get everything inside the pair of brackets.
The contents may change and the max and min may not exist in certain cirumstances.
get(max(fieldname1),min(fieldname2),fieldname3)where(something=something) sort(fieldname2 asc)
The where() and sort() are not guaranteed to be there.
There may be spaces b...
I'm trying to build a bbcode parser, but I'm having quite some problems figuring out how to avoid matching too widely. For example I want to implement a [list] to conversion like this:
\[list\](.*)\[/list\]
would be replaced by this:
<ul>$1</ul>
This works fine, except if I have two lists where the regular expression matches the b...
Let’s say that you decide to change the name of Stack Overflow to Frack Overflow.
Now, in your code you already have dozens of objects and variables and selectors with some variation of the name "Stack". You want them to now be replaced with "Frack".
So my question is, would you opt to run your entire codebase through a regular expres...
I want to match a web address through regex which should capture http://www.google.com as well as www.google.com i.e. with and without protocol.
...
How can I fetch a domain name from a URL String?
Examples:
+----------------------+------------+
| input | output |
+----------------------+------------+
| www.google.com | google |
| www.mail.yahoo.com | mail.yahoo |
| www.mail.yahoo.co.in | mail.yahoo |
| www.abc.au.uk | abc |
+-----------...
I am trying to search a text file for a certain pattern. If this pattern occurs then it means that the rest of the line is not needed and therefore can be deleted.
I have tried using the following commands, but so far have been unsuccessful.
:%s/{pattern}/d$
:g/{pattern}/d$
If anyone has any suggestions they would be greatly appreci...
Consider the following function arguments (they are already extracted of the function):
Monkey,"Blue Monkey", "Red, blue and \"Green'", 'Red, blue and "Green\''
Is there a way to extract arguments to get the following array ouput using regexp and stripping white spaces:
[Monkey, "Blue Monkey", "Red, blue and \"Green'", 'Red, blue an...
I'm not very good with regex and i've been kinda scratching my head on this one. I got the following php code using preg_match which is supposed to match all characters in the registry pathing except for the record number... which in this case is "record??]":
<?php
$reg_section = "[HKEY_LOCAL_MACHIN\SOFTWARE\INTERSTAR TECHNOLOGIES\XM...
I have an log file that I need to extract specific patterns from. I need to find and then process them into a new file. grep on Linux would usually do the trick but the regular expression spans multiple lines, which I understand grep does not do.
here is an example from my log/debug file:
Da:
1.328 0.5045
Db:
0.6415 0.1192
La...
Hi! I'm creating a ladder system for some games and I've encountered a problem regarding the clan base system. You see, every player who joins are parsed and put into a players table. Like this:
chelsea | gordon
chelsea | jim
chelsea | brad
OR...
CLANTAG|> jenna
CLANTAG|> jackson
CLANTAG|> irene
So, what I want: I wanna grab the C...
We are using the following to do an email validation in ASP.NET:
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
How can this be modified to ignore leading and trailing spaces?
The actual trimming we handle in code on postback but the validator is triggering as being invalid if the user has an extra space often due to copying and paste....
I need a regular expression that matches APA format references.
I currently have this:
/([A-Z][a-zA-Z\-\:\'\s\´]{3,}\, ([a-zA-Z]\.[\s|,|.]| &?){1,}){1,}\(\d\d\d\d(, [A-Z][a-z\- ]*\d\d?|)\)\.[a-zA-Z\-\:\'\s]{3,}\.[a-zA-Z\-\s]+\,[ ]*\d\d(\(\S\))*,\d+.\d+./
It only catches 10 and is fragile as hell.
I only need journal articles - not b...
Given a string like this:
<a href="http://blah.com/foo/blah">This is the foo link</a>
... and a search string like "foo", I would like to highlight all occurrences of "foo" in the text of the HTML -- but not inside a tag. In other words, I want to get this:
<a href="http://blah.com/foo/blah">This is the <b>foo</b> link</a>
Ho...