Trying to parse some strings and I could really use some help with a regular
expression (and how to test it in php).
My sample strings:
Bob 1/0/X0 134 128 1 5 Data
A comment line
Bob 1/0/X2 84 82 25 0 COMPARTMENT1-3
Bob 1/0/X1 1710 167 0 4 123 N/A
Bob 11/0/X3 84 7 0 6 Data
I'm trying to identify any string that starts with "Bob", then a space, then
a digit OR a space, then #/#/X#, three spaces, a 1 to 4 digit number, some
spaces, a 1 to 4 digit number, some spaces, a 1 to 4 digit number, some
spaces, a 1 to 4 digit number, some spaces, some alpha characters.
In my sample, the first, third and fifth strings would test positive.
I'm sure I've botched this up, but this is what I have so far.
if (
ereg('^Bob..[0-9]/[0-9]/X[0-9]\b[0-9]{1,4}(.{9,13})[0-9]{2,4}(.{9,13})[A-Za-z]*'
, $line ) ) { ...mycode... } 2 1249
On Fri, 20 Jul 2007 11:11:42 +0200, Noozer <do*******@me.herewrote:
Trying to parse some strings and I could really use some help with a
regular
expression (and how to test it in php).
My sample strings:
Bob 1/0/X0 134 128 1 5 Data
A comment line
Bob 1/0/X2 84 82 25 0 COMPARTMENT1-3
Bob 1/0/X1 1710 167 0 4 123 N/A
Bob 11/0/X3 84 7 0 6 Data
I'm trying to identify any string that starts with "Bob", then a space,
then
a digit OR a space, then #/#/X#, three spaces, a 1 to 4 digit number,
some
spaces, a 1 to 4 digit number, some spaces, a 1 to 4 digit number, some
spaces, a 1 to 4 digit number, some spaces, some alpha characters.
In my sample, the first, third and fifth strings would test positive.
I'm sure I've botched this up, but this is what I have so far.
if (
ereg('^Bob..[0-9]/[0-9]/X[0-9]\b[0-9]{1,4}(.{9,13})[0-9]{2,4}(.{9,13})[A-Za-z]*'
, $line ) ) { ...mycode... }
preg_match('%
^Bob #start of string
\s+ #arbitrary whitespace
[0-9]{1,2} #1 or 2 digits
/ #literal
[0-9] #digit
/X #literal
[0-9] #digit
\s+ #arbitrary whitespace
[0-9]+ #digit(s)
\s+ #arbitrary whitespace
[0-9]+ #digit(s)
\s+ #arbitrary whitespace
[0-9]+ #digit(s)
\s+ #arbitrary whitespace
[0-9]+ #digit(s)
\s+ #arbitrary whitespace
.+ #rest of data
%ix',$line);
Then again: http://www.php.net/sscanf
$lineparts = sscanf($line,'Bob %d/%d/X%d %d %d %d %d %s');
--
Rik Wasmus
"Noozer" <do*******@me.herewrote in message
news:i%_ni.132646$1i1.126404@pd7urf3no...
Trying to parse some strings .... My sample strings:
Bob 1/0/X0 134 128 1 5 Data
A comment line
Bob 1/0/X2 84 82 25 0 COMPARTMENT1-3
Bob 1/0/X1 1710 167 0 4 123 N/A
Bob 11/0/X3 84 7 0 6 Data
I'm trying to identify any string that starts with "Bob", then a space,
then a digit OR a space, then #/#/X#, three spaces, a 1 to 4 digit number,
some spaces, a 1 to 4 digit number, some spaces, a 1 to 4 digit number,
some spaces, a 1 to 4 digit number, some spaces, some alpha characters.
In my sample, the first, third and fifth strings would test positive.
preg_match('%^Bob\s+\d{1,2}/\d/X\d\s+\d{1,4}\s+\d{1,4}\s+\d{1,4}\s+\d{1,4}\s+[a-z]+.+%ix',$exstr);
I think previous reply may also match your example 4
hth
Alan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steve |
last post by:
Hello, I am writing a script that calls a URL and reads the resulting
HTML into a function that strips out everthing and returns ONLY the
links, this is so that I can build a link index of various...
|
by: Kenneth McDonald |
last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate
feedback, suggestions, and criticism as I work towards finalizing the
API and feature sets. rex is a module intended to make...
|
by: hillcountry74 |
last post by:
Hi,
I'm stuck with this regular expression from past 2 days. Desperately
need help.
I need a regular expression that will allow all characters except these
*:~<>'
This is my code in...
|
by: Buddy |
last post by:
Can someone please show me how to create a regular expression to do the
following
My text is set to
MyColumn{1, 100} Test
I want a regular expression that sets the text to the following...
|
by: sasifiqbal |
last post by:
Hi All,
I have following text Template that needs to be parsed using Regular
Expression
-- Test Template
This is a Test Template for <#OrderNumber/>
Sender Message is <#SENDERMESSAGE/>
|
by: John |
last post by:
I am new in Regular Expression. Could someone please help me in following
expression?
1. the string cannot be empty
2. the string can only contains AlphaNumeric characters. No space or any...
|
by: Rahul |
last post by:
Hi Everybody
I have some problem in my script. please help me. This is script file.
I have one *.inq file. I want run this script in XML files. But this
script errors shows . If u want i am...
|
by: JNariss |
last post by:
Hello,
I am fairly new to asp and jscript and am now in the process of
learning some form validation. I am taking one step at a time by
validating each field and testing it before moving onto...
|
by: Zach |
last post by:
Hello,
Please forgive if this is not the most appropriate newsgroup for this
question. Unfortunately I didn't find a newsgroup specific to regular
expressions.
I have the following regular...
|
by: Mr.Steskal |
last post by:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression
Help
--------------------------------------------------------------------------------
I need help writing a regular...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |