sudhakar_koundinya
asked on
What is the Regular Expression
Hello All,
What is the regular expression for following content
library <somelibrary>;
use <somelibrary>;
I am using POSIX regular expression library
Thanks Sudhakar
What is the regular expression for following content
library <somelibrary>;
use <somelibrary>;
I am using POSIX regular expression library
Thanks Sudhakar
if you are talking of only one space ...
library\s.*;
for many spaces
library\s*.*;
library\s.*;
for many spaces
library\s*.*;
ASKER
it is white space means possibliity of tabs also
ASKER
any way let me try for both with that regular expression
String <SPACE> <SOME String> <open bracket> <possiblity of space> <close bracket> <Semi colon>
If this is the situation
will this expression works??
library\s.*(\s.);
String <SPACE> <SOME String> <open bracket> <possiblity of space> <close bracket> <Semi colon>
If this is the situation
will this expression works??
library\s.*(\s.);
You mean:
^\S+(\s|\t)+\S;$
(not sure, but that might work)
^\S+(\s|\t)+\S;$
(not sure, but that might work)
For your String <SPACE> <SOME String> <open bracket> <possiblity of space> <close bracket> <Semi colon>, this should work:
library\s.*?\(\s*\);
might work.
library\s.*?\(\s*\);
might work.
library\s.*\(\s*\); probably should work also, I'm not sure why your example above had a ".", because if you have a ".", it means you can have anything in the bracket, even digits, etc. so you would just need:
library\s.*(.*);
library\s.*(.*);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try
library|use\s+<\w+>;
library|use\s+<\w+>;
ASKER
avizit,
your last expression has worked for me. But what is expression if it contains ()
for example
method test();
or
method test1( );
your last expression has worked for me. But what is expression if it contains ()
for example
method test();
or
method test1( );
ASKER
avizit,
your last expression has worked for me. But what is expression if it contains ()
for example
method test();
or
method test1( );
your last expression has worked for me. But what is expression if it contains ()
for example
method test();
or
method test1( );
that should depend on if you are going to have something between the braces or its going to be empty
method[[:space:]]+.+\([[:s pace:]]+\) ;
i.e you may have to escape the ( )'s
method[[:space:]]+.+\([[:s
i.e you may have to escape the ( )'s
ASKER
ok,
same thing is working for this also
same thing is working for this also
ASKER
one last question
How to handle if the sting contains % and/or *
How to handle if the sting contains % and/or *
you should escape them with a backslash
use \% , \* for a literal % and *
use \% , \* for a literal % and *
ASKER
ok,
let me try
Thanks for continuous helping
let me try
Thanks for continuous helping
ASKER
How to handle case insensitve strings??
for POSIX regular expressions you can use
[:alpha:] to denote alphanumeric charcters
[:alpha:] to denote alphanumeric charcters
ops i mean
[:alpha:] for alphabetic
[:alnum:] for alpha numeric
[:digit:] for digits
[:lower:] for lower case
[:upper] for upper case
[:alpha:] for alphabetic
[:alnum:] for alpha numeric
[:digit:] for digits
[:lower:] for lower case
[:upper] for upper case
ASKER
[:lower:] for lower case
[:upper] for upper case
checks explicitly for lower case or upper case. I need to have a mixed case.
Any other Ideas
Thanks
Sudhakar
so you use [:alpha:] for both
and [:alnum:] for alphanumeric ie
[a-zA-Z0-9] you can use this too instead of the above for alphanumeric
for only alphabetic of both cases you can use
[a-zA-Z]
[a-zA-Z0-9] you can use this too instead of the above for alphanumeric
for only alphabetic of both cases you can use
[a-zA-Z]
ASKER
Hmm,
if I have some thing like this
Library test;
or
library test;
or
LIBRARY test;
then
library[[:space:]]+.+; will work for second case only
if I have some thing like this
Library test;
or
library test;
or
LIBRARY test;
then
library[[:space:]]+.+; will work for second case only
Regular expressions are NFG for parsing perl syntax, since a #comment can appear anywhere. Or a \escape.
Perl is just too loose a syntax to be parsed by anything as regimented as regular expressions.
Perl is just too loose a syntax to be parsed by anything as regimented as regular expressions.
oh that you you can use
(library|LIBRARY) if you want to match only those two forms
you can also you
[lL][iI][bB][rR][aA][rR][y Y]
if you want to match
library
Library
LIbrary .. and so on
yhou might be able to use /library/i i.e the i switch which makes it case insenstive .. not sure if POSIX regular expressions allows it or not
(library|LIBRARY) if you want to match only those two forms
you can also you
[lL][iI][bB][rR][aA][rR][y
if you want to match
library
Library
LIbrary .. and so on
yhou might be able to use /library/i i.e the i switch which makes it case insenstive .. not sure if POSIX regular expressions allows it or not
ASKER
thanks :-)
The accepted answer looks rather loose to me ;-)
*shrug* .:)
but if any of the above were wrong or incorrect , i guess you can always point it out. Sudhakar can always unaccept the question. I mean that's better than having a wrong solution.
/abhijit/
but if any of the above were wrong or incorrect , i guess you can always point it out. Sudhakar can always unaccept the question. I mean that's better than having a wrong solution.
/abhijit/
Up to him, but of course it'll also match
library of donald duck;
;-)
library of donald duck;
;-)
right :) thanks
guess could have used [:alnum:] instead of the "."
guess could have used [:alnum:] instead of the "."
... then that would just leave
a. the left angle bracket
b. the right angle bracket
c. the alternation between 'use' and 'library'
;-)
a. the left angle bracket
b. the right angle bracket
c. the alternation between 'use' and 'library'
;-)
the alternation I understand but what with the 'brackets' ?
Maybe he didn't mean to match '<' and '>' ..?
oh okay then i can't help atleats on this .. i can only do what is asked :)
BUt thanks nonetheless for pointing out the error :)
BUt thanks nonetheless for pointing out the error :)
:-)
ASKER
String <SPACE> <SOME String> <Semi colon>