What is the best way to validate a crontab entry with PHP? Should I be using a regex, or an external library? I've got a PHP script that adds/removes entries from a crontab file, but want to have some way to verify that the time interval portion is in a valid format.
...
I'm creating a CSS editor and am trying to create a regular expression that can get data from a CSS document. This regex works if I have one property but I can't get it to work for all properties. I'm using preg/perl syntax in PHP.
Regex
(?<selector>[A-Za-z]+[\s]*)[\s]*{[\s]*((?<properties>[A-Za-z0-9-_]+)[\s]*:[\s]*(?<values>[A-Za-z0-9...
A string will be made up of certain symbols (ax,bx,dx,c,acc for example) and numbers.
ex:
ax 5 5
dx 3 acc
c ax bx
I want to replace one or all of the symbols (randomly) with another symbol of the same set. ie, replace one of {ax,bx,dx,c,acc} with one of {ax,bx,dx,c,acc}.
replacement example:
acc 5 5
dx 3 acc
c ax bx
or
c 5 5
dx 3 acc
...
I have several strings in the rough form:
[some text] [some number] [some more text]
I want to extract the text in [some number] using the Java Regex classes.
I know roughly what regular expression I want to use (though all suggestions are welcome). What I'm really interested in are the Java calls to take the regex string and use it ...
I'm matching identifiers, but now I have a problem: my identifiers are allowed to contain unicode characters. Therefore the old way to do things is not enough:
t_IDENTIFIER = r"[A-Za-z](\\.|[A-Za-z_0-9])*"
In my markup language parser I match unicode characters by allowing all the characters except those I explicitly use, because my m...
Hi Guys
I have a wysiwyg editor in my back end, and it is tripping up the first regular expression I wrote. This is in PHP4, using preg_replace(). I'm capturing the URI and linked text.
@<a\shref=\"http[s]?://([^\"]*)\"[]>(.*)<\/a>@siU
The client wanted all external links to open in a new window, so that's the expression I was using ...
I have sets of 5, 6 and 7 digit numbers. I need them to be displayed in the 000/000/000 format. So for example:
12345 would be displayed as 000/012/345
and
9876543 would be displayed as 009/876/543
I know how to do this in a messy way, involving a series of if/else statements, and strlen functions, but there has to be a cleaner wa...
I'm using an HTML sanitizing whitelist code found here:
http://refactormycode.com/codes/333-sanitize-html
I needed to add the "font" tag as an additional tag to match, so I tried adding this condition after the <img tag check
if (tagname.StartsWith("<font"))
{
// detailed <font> tag checking
// Non-escaped expression (for tes...
I am trying to do a search in my Eclipse (Java) workspace to find all instances of static variables that are not final.
I tried various regex's but they do not result in any matches. Can someone suggest a regex that will match all lines containing 'static' and not containing 'final', and not ending in a '{'
The last part about not endi...
I have a set of templates for emails that my app sends out. The templates have codes embedded in them that correspond to properties of my business object. Is there a more elegant way than calling string.Replace("{!MyProperty!}", item.MyProperty.ToString()) a zillion times? Maybe Xml Transform, regular expressions, or some other magic? I'...
I'm developing an algorithm to parse a number out of a series of short-ish strings. These strings are somewhat regular, but there's a few different general forms and several exceptions. I'm trying to build a set of regexes that will handle the various forms and exceptions; I'll apply them one after another to see if I get a match.
One ...
When using grep --color=always I can get pretty color highlighting for regex matches.
However, grep only returns lines with at least one match. Instead, I am looking for a way to simply highlight regex matches, while leaving all other input alone, without dropping lines without any matches.
I have tried to get color working with sed, ...
I'm looking for Python code that removes C and C++ comments from a string. (Assume the string contains an entire C source file.)
I realize that I could .match() substrings with a Regex, but that doesn't solve nesting /*, or having a // inside a /* */.
Ideally, I would prefer a non-naive implementation that properly handles awkward case...
if(!eregi("^([0-9a-z_\[\]\*\- ])+$", $subuser))
$form->setError($field, "* Username not alphanumeric");
Can anybody tell me why it is not allowing characters such as - and *?
if(!eregi("^([0-9a-z])+$", $subuser))
$form->setError($field, "* Username not alphanumeric");
That is the original piece of code. A friend changed it t...
Assuming a Perl script that allows users to specify several text filter expressions in a config file, is there a safe way to let them enter regular expressions as well, without the possibility of unintended side effects or code execution? Without actually parsing the regexes and checking them for problematic constructs, that is. There wo...
I am trying to write a replacement regular expression to surround all words in quotes except the words AND, OR and NOT.
I have tried the following for the match part of the expression:
(?i)(?<word>[a-z0-9]+)(?<!and|not|or)
and
(?i)(?<word>[a-z0-9]+)(?!and|not|or)
but neither work. The replacement expression is simple and current...
I need to write a regular expression that finds javascript files that match
<anypath><slash>js<slash><anything>.js
For example, it should work for both :
c:\mysite\js\common.js (Windows)
/var/www/mysite/js/common.js (UNIX)
The problem is that the file separator in Windows is not being properly escaped :
pattern = Pattern.compil...
Wanna write a RegEx to validate a driving license.
if it doesn't start with (US, CA, CN) then it has to be followed with XX and after that with any number of Alpha numeric letters.
So for example if the driving license starts with GB then it has to be followed with XX
GBXX12345363
However if it starts with US then we don't care what ...
I'm developing a poker game in C#. At the moment I'm trying to get the players hand score using RegEx. I search the string (composed of the cards suit and number) and look for suits or numbers to match the RegEx. If i get 2 matches then the player has a pair, 3 matches he has 3 of a kind.
I have 3 classes at the moment, a Card class (w...
Just for my own purposes, I'm trying to build a tokenizer in Java where I can define a regular grammar and have it tokenize input based on that. The StringTokenizer class is depracated, and I've found a couple functions in Scanner that hint towards what I want to do, but no luck yet. Anyone know a good way of going about this?
...