Link to home
Start Free TrialLog in
Avatar of sudhakar_koundinya
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
Avatar of sudhakar_koundinya
sudhakar_koundinya

ASKER

I mean if the strings comes some thing like

String <SPACE> <SOME String> <Semi colon>      
if you are talking of only one space ...

library\s.*;  

for many spaces

library\s*.*;


it is white space means possibliity of tabs also
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.);  
Avatar of Zyloch
You mean:

^\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*\); 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.*(.*);  
ASKER CERTIFIED SOLUTION
Avatar of avizit
avizit

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try

library|use\s+<\w+>;
avizit,

your last expression has worked for me. But what is expression if it contains ()

for example

method test();
or

method test1(   );            


avizit,

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:]]+.+\([[:space:]]+\);


i.e you may have to escape the ( )'s

ok,

same thing is working for this also
one last question

How to handle if the sting contains % and/or *

you should escape them with a backslash

use \%  , \* for a literal % and *
ok,

let me try


Thanks for continuous helping
How to handle case insensitve strings??
for POSIX regular expressions you can use


[: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

[: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]
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






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.

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][yY]  
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
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/
Up to him, but of course it'll also match

library of donald duck;

;-)
right :)  thanks
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'

;-)
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 :)
:-)