Regular Expression For Comma-delimited Pairs
I have a textarea form field for inputting (or pasting) pairs of data.
I need a regular expression pattern to validate each line for the following
double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return
The following comes close, but doesn't check for a carriage return at the
end of each line:
^"([0-9]?)+"([,]s?"([A-Za-z0-9]+)")*$
For example the following would return true:
"1","John"
"2","Paul"
"3","George"
"4","Ringo"
View Complete Forum Thread with Replies
Related Forum Messages:
Regular Expression :: Find Word Matches To Words In A Comma-delimited List
What's the *right* way to find word matches to words in a comma-delimited list. For example, if I have the following comma-delimited list of categories in a mysql db field: gameboy, nintendo, playstation and I do a search, I know I can use regexp to do something like: select * from categories where regexp 'gameboy,' Notice that I have the comma in there to match the whole word and the comma without matching part of a word (to prevent unwanted matches such as "play" to "playstation" or "game" to "gameboy"). The problem I'm running into is words that match that match the end of each word next to the comma (in this example, "boy" and "station"). What's the right way to match a word *exactly* using regexp *without* also matching *part* of a word.
View Replies !
Numeric/alpha Pairs Regular Expression
I need a comma delimited regular expression pattern with the followng restrictions: no leading and trailing white space no trailing comma double quoted numeric/alpha pairs each pair on a separate line For example: "1","Peter" "2","Paul" "3","Mary"
View Replies !
Regular Expression That Will Split A String Into Several Parts With ',' (comma)
with a regular expression that will split a string into several parts with ',' (comma) as the separator, but NOT where the separator is enclosed in parentheses. For example, take the string "field1, CONCAT(field2,' ', field3) as field23, field4". I would like to be able to split this into the following: [0] field1 [1] CONCAT(field2,' ', field3) as field23 [2] field4
View Replies !
Comma Delimited File
I am trying to read comma delimited rows of text. The problem is that some fields may be encapsulated in "" - particularly the text fields but not numeric fields. Is there a simple efficient way to parse the fields with comma but also strip off the "" encapsulating some of the fields with php? The problem is the "" encapsulation is optional. Some fields will have it, some won't.
View Replies !
Statement With Comma Delimited Fields
I'm hacking into my vBulletin forum to use individuals current usernames, passwords, and membergroups to setup a premium portion of my site. I have the following query: PHP Code: $users = mysql_query("SELECT * FROM user WHERE username='$username' AND membergroupids=ཛྷ'"); With this query my login works for those who have signed up for the premium content on the forum. One problem is if the members join multiple user created member groups, they're membergroupids will be like 32,10,34. I need my query to find if they belong to 32 and if so allow them access. So, if they belong to 32,10,34 then they should be allowed to enter, but if they belong to 10,34 they should not.
View Replies !
Comma Delimited Csv Has Commas Inside Fields
I need to import a CSV file into a database daily. That operation in itself is simple enough but the trouble is that some fields are quoted because they have commas inside them. How do I handle this with my import script? It would be much better if the CSV was created with all fields quoted or used a different delimited but sadly that is not an option.
View Replies !
Stripping Quotes Out Of A Comma Delimited File?
I have a flat file that I'm trying to stick into a MySQL database. One record per line, multiple fields per record, and many of them are null fields which are just double quotes without a space between. It's probably nothing really major for people who have done this before, but I'm a bit stumped. The file is comma delimited. Every field is surrounded by double quotes. I've done quite a bit of searching, on the php site and elsewhere, but I can't seem to get it to strip the quotes out so I can explode the file line by line to grab the fields.
View Replies !
Converting Comma Delimited Field Into Array
I have an array that goes into a MySQL database (via PHP). The only way I could find to insert them into the database was using implode. It goes into the database just great, comma separated (although I would like each to go into it's own field, but it's okay for now). The problem comes when I try to display it. Since it's comma delimited it display only the first item in the array. But there are multiple rows that should be displayed. I'm not sure how to explode it so that it will display them all. I've tried a loop but that just looped the first item in the field (the first part of the array). Code:
View Replies !
File Parsing Function For Tab Or Comma Delimited Files
I need a way to parse a file based on the delimitation of either tab or comma. Does anyone know the best way to do this that is the easiest? Also the file I am parsing might have a few empty strings between delimitation. I know about preg_split so if this is the only way could someone provide a link that explains regular expressions because i dont get it.
View Replies !
Create A Comma Delimited String That I Can Convert To An Array Using Explode();.
I am attempting to create a comma delimited string that I can convert to an array using explode();. I have the following code: Code: $cPath_new_a = tep_get_path($categories['categories_id']); $cPath_new_b = str_replace("cPath=", "", "$cPath_new_a"); $cPath_new_c = str_replace("_", "", "$cPath_new_b"); $cPath_new_d = substr("$cPath_new_c", -2, 2); $cPath_new_e = $cPath_new_d . ","; echo $cPath_new_e; This outputs 23,53, I need it to output 23,53 Using the substr($cPath_new_e, 0, -1); and/or rtrim() method to remove the last character for some reason removes all of the commas. Am I approaching this the right way?
View Replies !
Need Help With A Regular Expression
I need to replace all quotes with an arbitrary character - but only if they are between tags: <span class="large">big text</span> This would become something like: <span class=QlargeQ>big text</span> I've been trying lots of permutations of this, without success: $txt = preg_replace("/<(.*?)("){1,}(.*?)>/", "<1Q3>", $txt);
View Replies !
Regular Expression To Get Rid Of <br>
I've got a tag(let's call it [tag]) that has several <br>s in front of it. I want to get rid of the <br>s. The problem here is that there are an unknown amount of <br>s before the tag, and an unknown amount of spaces in between seemingly random placements of <br>s. Here is an example, to clarify. $str = "<br> <br><br><br> <br><br> <br> <br> [tag]"; I just randomly wrote this, so this isn't real, but it's similar to my situation. The regular expression I wrote to get rid of one <br> was... $pattern = "<br>[tag]"; then the replacement would be.... $replacement = "[tag]";
View Replies !
Regular Expression Q
I have an HTML file and want to convert all tags to lowercase, but leave the attributes alone. For instance: <SOME TAG ATTRIBUTE="Text THAT may be Upper"></SOME TAG> Needs to be converted to: <some tag attribute="Text THAT may be Upper"></some tag> I can easily convert everything in the tag to lower using '<.*?>' but am stuck getting PHP to ignore whatever is in quotes.
View Replies !
Value From A URL Using Regular Expression
We have a URL than can be any one of the following http://mydomain.com/CA/ http://mydomain.com/123CA/ http://mydomain.com/123CA456/ http://mydomain.com/123CA456/index.htm In need a little help with the regular expression that would extract the value after the domain name. We want $myvalue to be equal to the part of the URL just after the domain name, but not including anything after the subsequent slash"/". for example, http://mydomain.com/123CA456/index.htm should save as: $myvalue = 123CA456 any ideas of the regular expression we could use?
View Replies !
Regular Expression In PHP
How can I get all the values which are between Name tags as follows: <emp> <name>N1</name> <age>1</age> <name>N2</name> <age>2</age> <name>N3</name> <age>3</age> <name>N4</name> <age>4</age> </emp>
View Replies !
Regular Expression [Help]
I must find a regular expression to find every declaration af a variable in a php programm..... I tried: /$([a-zA-0-9_])*(s|S)=(s|S)/is But it doesn't reall go :-( I've got no expreience in things like regular expressions... And: Is it possible to look if the decaration ist in ' or " ? If eyes: how and if no :-@
View Replies !
Regular Expression Help
I am using the preg_match function (in PHP) that uses perl regular expressions. Apparently I don't really understand regular expressions though. If this is the regular expression /^s*(d+.d+)|(.d+)|(d+)s*$/ How does this: 40:26:46.302N 79:56:55.903W match? I thought when I added the ^ and $ that meant it had to match the whole thing? It seems to only be matching .302
View Replies !
Using Regular Expression
I am using regular expression. But I have some problems with it, look at the following code: Code: <HTML> <HEAD><TITLE>Finding substring</TITLE></HEAD> <BODY> <?PHP $input = "maths 89 c++ 92 java 85 uml 80"; ereg("[0-9]*",$input,$regs); echo "Scores:<br>"; echo "num: " . count($regs); for($i=0;$i<count($regs);$i++){ echo "$regs[$i] "; } ?> </BODY> </HTML>
View Replies !
A Regular Expression
Is there a way to do a greater than and less than in a regular expression? I am looking to list only images that are less than 10 in there name. pan1.jpg pan2.jpg pan3.jpg pan4.jpg ... up to pan10.jpg I was able to get it to just list pan1.jpg to pan9.jpg using the following expression, (pan[^[1-9]$]).jpg. I need it to include the 10 as well. I like to know if less than and greater than are available.
View Replies !
Regular Expression :: [^a-zA-Z0-9@._]
I have been looking around at several tutorials about building a custom simple CMS. I found one simple enough that I thought I could use this to build my own upon, I wanted to start adding as much security I can to it but I'm lacking in knowledge. I thought the first steps I would take would be to place all of my includes above root directory, and now I'm thinking of adding a regular expression to filter the data entered from my form. I'm a little-bit lost. I was thinking maybe something like: [^a-zA-Z0-9@._] what I think this regular expression is doing is, matching anything other than the ranges and extra characters I listed. So I'm guessing I would use an if statement with that regular expression, saying if anything other than these characters are found, do not send the query, else send it.
View Replies !
Regular Expression
<?php $string = "This is a test"; echo str_replace(" is", " was", $string); echo ereg_replace("( )is", "1was", $string); echo ereg_replace("(( )is)", "2was", $string); ?> output is like:This was a testThis was a testThis was a test.
View Replies !
Getting Variables Out Of A Regular Expression
If i need to do some big time parsing, and I need what I'm parsing out to go into nice little varaibles, how do I do that without a million ugly preg_split functions? Say I have this line: "blah blah blah ~~ [THIS] -- blah blah -- [THAT]" How could I end up with $this and $that, containing "[THIS]" and "[THAT]" respectively, possibly in only a few lines of code?
View Replies !
Regular Expression Negation
I'm trying to negate a phrase rather than just a single character in a regular expression. Is there a syntax for multiple character negation? For example, if 'Brenda Brown' and 'Brenda Jones' are OK, but not 'Brenda Smith'? Regex is such a powerful tool -surely there's a multiple negation operator.
View Replies !
Regular Expression Help Please (hopefully Simple)
I've got a file with this in it: [Event "Some string data"] The data I'd like extracted is within the quotes: Some string data I can read the file out and extract (using string positions) the data I'd like but it would neater if I use a regular expression. Only problem is I've never seen a working example of this type of extraction and am completely new to PHP.
View Replies !
Problem With A Regular Expression
I'm having a regular expression problem. I need it to match all occurences of "href="(not http)<whatever-else"". My attemps have been: href="[^h][^t][^t][^p][^:][^/][^/][^"]+", which works, but will fail on things like "href="attribute.html"", as there are t's where the regex doesn't expect them. Thus, this attempt can be ditched. href="(^http://)["]+", which doesn't work, and ends up matching only things like "href="httpandthensomemore.html"" and I couldn't really figure out more. I need a regular expression that only matches the WORD http, not each individual character, and I need it to match the whole word, as this is not used as a check for links starting with http, but for replacing relative links with absolute ones in the following piece of PHP code: preg_replace("/href="<regex that works... hopefully>"/", "http://address.com/$1", $pieceOfHTML); And I chose to post this here and not in the PHP section, as it's not concerning the PHP but the regular expression....
View Replies !
Regular Expression L & U Switches
In the following regular expression: $_="BCADeFGHIJKL"; if (/L[w]E/) { print "true"} else { print "false" }; if (/U[w]E/) { print "true"} else { print "false" }; why the first one print true while the second one print false? Can someone explain L U?
View Replies !
Regular Expression Pattern
I'm having trouble with a regular expression pattern. I want to match "c" or "k" or "ck" but not "ch". It's that last bit that's giving me trouble. Example: Match "sic" or "sik" or "sick" or "sikc" not "sich" Here's the pattern that I'm using so far: /(^|[^a-zA-Z])(s+|$+|&+)(W|( )|(<.*> )|s|_)*(a+|e+|i+|o+|u+|*+|&+|^+|%+|$+|#+|@+|!+)(W|( )|(<.*> )|s|_)*(c+|k+|((c+)(W|( )|(<.*> )|s|_)*(k+))|((k+)(W|( )|(<.*> )|s|_)*(c+)))([^a-zA-Z]|$)/gi
View Replies !
Preg_match_all // Regular Expression
right now the script just browse through the url, and returns all the links in the page, but what i would like to try, is to make it return the links AND the text between the <a href and </a>, so if a link says PHP Code:
View Replies !
Regular Expression Troubles
I'm not the most competent person when it comes to regular expressions. Needless to say, i attempted my own pattern and have manage to balls something up cronic The following is the pattern that i wish to convert: PHP Code:
View Replies !
How To Refine My Regular Expression?
What I want to do is replace all instances of $searchterm in $text with the string "^^^^^", but only if $searchterm is within an HTML tag. For example, if $text is "<pre>Hello!</pre>", and $searchterm is "pre", I want the result to be: "<^^^^^>Hello!</^^^^^>". Here's what I have now: $text = preg_replace ( "/(<.*?)($searchterm)(.*?> )/", "1^^^^^3", $text ); Unfortunately, this doesn't work. For example, if $text is "<b>pre</b>" and $searchterm is "pre", the pre gets replaced. Why? Because while the "pre" may not be in an HTML tag, technically it's still between brackets - the first and last characters of $text.
View Replies !
Why Does This Regular Expression Fail?
Suppose I have these five lines in a file somewhere: <p>This entry should belong to: <select name="formInputs[id_of_neighborhood_to_which_this_belongs]"> <option value="">(No choice made)</option> <?php getDatabaseTableValuesInOptionTags("neighborhoods", "id", "state"); ?> </select> Suppose I open this file and read the contents into a string called $string. Suppose I then give the string to this function: function matchAllPhpFunctionsInString($subject=false) { // 11-08-06 - this is being called in importForm $pattern = "<"; $pattern .= "?php.*(.*); ?"; $pattern .= ">"; $pattern = "/$pattern/"; preg_match_all($pattern, $subject, $matches); // print_r($matches); // 09-19-06 - there is no point returning a 2 dimensional array, so we will make // it one dimensional. $arrayOfPhpFunctionNames = $matches[0]; return $arrayOfPhpFunctionNames; } This function is suppose to find the PHP command. It works on other pages, but not the one I've posted above. Why is that? Why would this regular expression not find this PHP command?
View Replies !
Selecting With Php (regular Expression?)
first a user can pick a name ($name) and gender ($gender; value is "m" or "f"). in mysql, i'm going to have a whole blob of text. here's a short example: [[name]] said {he|she} was going to the store today. i can change [[name]] to $name but is there a way i can use "he" when $gender is "m' and "she" when $gender is "f"? i'm guessing with regular expression? and in the braces may contain longer things that may contain spaces, etc. like: {hansome guy|cute girl} i'm not too good with regular expression, could someone come up with one that might work?
View Replies !
Regular Expression In A Form
I have used some of this code from the PHP manual, but I am bloody hopeless with regular expressions. Was hoping somebody could offer a hand. The output of this will put the name of a form field beside name. I want to get the following but not sure how to modify the code below. 1. Field Name (to appear beside NAME:) 2. Field Type (to appear beside TYPE:) 3. Field Value (to appear beside VALUE:) Make sense. It is part way there, just need some help finishing it. $filename = "form-eg.php"; // Open file to read HTML with Form code $fd = fopen ($filename, "rb"); $contents = fread ($fd, filesize ($filename)); preg_match_all ('/<input.*?names*=s*"?([^s>"]*)/i', $contents, $matches); // get all input fields and attributes and values for ($i=0; $i< count($matches[0]); $i++) { echo "matched: ".$matches[0][$i]."<br />"; echo "NAME: ".$matches[1][$i]."<br />"; echo "TYPE: ".$matches[3][$i]."<br />"; echo "VALUE: ".$matches[4][$i]."<br />"; } fclose ($fd); I will also need to run another check for:
View Replies !
Regular Expression Inquiry
I'm processing the following sequence with length more than 100k 1 cagatgctga taaaaaagtg tgttcctcat agcatttatt taattgaaat atttcaagaa 61 cttgaatgta ctaaaaattg agacaaacag tagcaaatca taaaaaaaaa ttgaagtgaa 121 ttttacaact ggattcatgt gcctaatatt ttcattggga agtggattca tgtttaacat 181 ttccattggg <snippet> i wrote a program <?php session_start(); if (isset ($_POST['seq']) ) $seq = $_POST['seq']; else $seq= $_GET['seq']; $seq = preg_replace("/[s 0-9]/", "", $seq); echo $seq; ?> but it generates an output of fragmented sequences (i.e. partially processed result), what is the problem?
View Replies !
Regular Expression (preg_replace)?
How can I write the thing below as a regular expression (preg_replace)? $array = array("-0", "-1", "-2", "-3", "-4"); $key = str_replace($array, "", $key); I am trying to learn regular expressions, but I find them hard and this seems like a really simple place to start....
View Replies !
Regular Expression : {link}
text with {link:pagehref}a link{/link}. replace to -> text with <a href="pagehref">a link</a> I tried several things but nothing seems to work... e.g. $value=preg_replace("/{link:(.+?)}(.+?){/link}/s","<a href="$1" target="_blank">$2</a>",$value);
View Replies !
|