Regular expressions for matching file path
Could someone give me idea that how can i compare a fixed path, with the paths user gives using regular expressions?
My fixed path is : src\com\sample\demo\work\gui\.**
and user may give like src\com\sample\demo\work\gui\test.jsp, src\com\sample\demo\work\gui\init.jsp etc.
Any ideas are appreciated and thanks in advance.
...and if you insist on using regexes, you'll have to double-escape the backslashes: if ( userString.matches("src\\\\com\\\\sample\\\\demo\\\\work\\\\gui\\\\.*") ) { Whether you use regexes or not, you'll save yourself a lot of hassle by converting all backslashes to forward slashes before you do anything with the strings: userString = userString.replace('\\', '/');
if ( userString.matches("src/com/sample/demo/work/gui/.*") ) {
// or...
if ( userString.startsWith("src/com/sample/demo/work/gui/") ) {
Similar Messages
-
How to form a regular expression for matching the xml tag?
hi i wanted to find the and match the xml tag for that i required to write the regex.
for exmple i have a string[] str={"<data>abc</data>"};
i want this string has to be splitted like this <data>, abc and </data>. so that i can read the splitted string value.
the above is for a small excercise but the tagname and value can be of combination of chars/digits/spl symbols like wise.
so please help me to write the regular expression for the above requirementyour suggestion is most appreciable if u can give the startup like how to do this. which parser is to be used and stuff like that
-
Urgent!!! Problem in regular expression for matching braces
Hi,
For the example below, can I write a regular expression to store getting key, value pairs.
example: ((abc def) (ghi jkl) (a ((b c) (d e))) (mno pqr) (a ((abc def))))
in the above example
abc is key & def is value
ghi is key & jkl is value
a is key & ((b c) (d e)) is value
and so on.
can anybody pls help me in resolving this problem using regular expressions...
Thanks in advance"((key1 value1) (key2 value2) (key3 ((key4 value4)
(key5 value5))) (key6 value6) (key7 ((key8 value8)
(key9 value9))))"
I want to write a regular expression in java to parse
the above string and store the result in hash table
as below
key1 value1
key2 value2
key3 ((key4 value4) (key5 value5))
key4 value4
key5 value5
key6 value6
key7 ((key8 value8) (key9 value9))
key8 value8
key9 value9
please let me know, if it is not possible with
regular expressions the effective way of solving itYes, it is possible with a recursive regular expression.
Unfortunately Java does not provide a recursive regular expression construct.
$_ = "((key1 value1) (key2 value2) (key3 ((key4 value4) (key5 value5))) (key6 value6) (key7 ((key8 value8) (key9 value9))))";
my $paren;
$paren = qr/
[^()]+ # Not parens
|
(??{ $paren }) # Another balanced group (not interpolated yet)
/x;
my $r = qr/^(.*?)\((\w+?) (\w+?|(??{$paren}))\)\s*(.*?)$/;
while ($_) {
match()
# operates on $_
sub match {
my @v;
@v = m/$r/;
if (defined $v[3]) {
$_ = $v[2];
while (/\(/) {
match();
print "\"",$v[1],"\" \"",$v[2],"\"";
$_ = $v[0].$v[3];
else { $_ = ""; }
C:\usr\schodtt\src\java\forum\n00b\regex>perl recurse.pl
"key1" "value1"
"key2" "value2"
"key4" "value4"
"key5" "value5"
"key3" "((key4 value4) (key5 value5))"
"key6" "value6"
"key8" "value8"
"key9" "value9"
"key7" "((key8 value8) (key9 value9))"
C:\usr\schodtt\src\java\forum\n00b\regex> -
Regular Expression for Match Pattern (string) Function
I need to find a variable length string enclosed by brackets and
within a string. Can't seem to get the regular expression right for
the Match Pattern function. I'm able to get the job done using the
Token function, but it's not as slick or tight as I'd like. Does
anybody out there have the expression for this?Jean-Pierre Drolet wrote in message news:<[email protected]>...
> The regular expression is "\[[~\]]*\]" which means:
> look for a bracket "\[" (\ is the escape char)
> followed by a string not containing a closing bracket "[~\]]*"
> followed by a closing bracket "\]". The match string include the
> brackets
>
> You can also read "Scan from String" with the following format:
> "%[^\[]\[%[^\[\]]" and read the 2nd output. The brackets are removed
> from the scanned string.
Thanks, Jean_Pierre
I did some more experimenting after posting and found that \[.*\] also
works with the match pattern function. Thanks for your input.
sm -
Regular Expression for match pattern
Hi guys, I need some help.
In one part of my test system, I give to the program a sequence of temperatures, which are numbers separated by a comma. Due to a possible error, the user can forget the coma, and the program gets unexpected values.
For example, "20, 70, -10" is a right value, whereas "20 70, -10" would be a wrong one.
Which regular expression will detect this comma absence?
Thanx in advance.OK, makes it more difficult (and more fun )
My original version failed also when the space was forgotten. DOH!
Try this version. It get's complicated cause the scan from string likes ignoring spaces... So we change the spaces
Hope this helps
Shane.
PS The ideas given by others are still a better solution, but if you're stuck........
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Attachments:
Check input string with commas(array).vi 39 KB -
Regular Expression for PathName???
Anyone have a "ready to go" regular expression for detecting a pathname?
for example I need to detect the following:
myfile.txt
./myfile.txt
../my-file.ini
/home/my-home/myFile.foo
etc.
Now, in a perfect world, it could also do Windows (or ANY OS for that matter) pathnames (though this is not terrbibly important for my case at least).
TIA,
/mimport java.util.regex.*;
* @author Ian Schneider
public class FileRegex {
static Pattern pattern;
/** Creates a new instance of FileRegex */
public FileRegex() {
public Pattern getPattern() {
if (pattern == null) {
pattern = Pattern.compile("([\\/]?(\\w+|\\.|\\.\\.)[\\/])*(\\w+)\\.?(\\w+)?");
return pattern;
public String[] parts(String path) {
Matcher m = getPattern().matcher(path);
if (m.find()) {
return new String[] { m.group(1),m.group(3),m.group(4) };
return null;
public boolean matches(String path) {
return getPattern().matcher(path).matches();
public static final void main(String[] args) throws Exception {
FileRegex regex = new FileRegex();
String[] files = {
"myfile.txt",
"../myfile.txt",
"./myfile.txt",
"/a/b/c/myfile.txt",
"/a/../myfile.txt",
"myfile"
for (int i = 0, ii = files.length; i < ii; i++) {
System.out.println( files[i] + " match " + regex.matches(files));
String[] pieces = regex.parts(files[i]);
if (pieces != null)
System.out.println(" path : " + pieces[0] + " file : " + pieces[1] + " ext : " + pieces[2]);
I will leave it to you as an excercise to add support for spaces in path names, different separator characters, etc.. -
"Match Regular Expression" and "Match Pattern" vi's behave differently
Hi,
I have a simple string matching need and by experimenting found that the "Match Regular Expression" and "Match Pattern" vi's behave somewhat differently. I'd assume that the regular expression inputs on both would behave the same. A difference I've discovered is that the "|" character (the "vertical bar" character, commonly used as an "or" operator) is recognized as such in the Match Regular Expression vi, but not in the Match Pattern vi (where it is taken literally). Furthermore, I cannot find any documentation in Help (on-line or in LabVIEW) about the "|" character usage in regular expressions. Is this documented anywhere?
For example, suppose I want to match any of the following 4 words: "The" or "quick" or "brown" or "fox". The regular expression "The|quick|brown|fox" (without the quotes) works for the Match Regular Expression vi but not the Match Pattern vi. Below is a picture of the block diagram and the front panel results:
The Help says that the Match Regular Expression vi performs somewhat slower than the Match Pattern vi, so I started with the latter. But since it doesn't work for me, I'll use the former. But does anyone have any idea of the speed difference? I'd assume it is negligible in such a simple example.
Thanks!
Solved!
Go to Solution.Yep-
You hit a point that's frustrated me a time or two as well (and incidentally, caused some hair-pulling that I can ill afford)
The hint is in the help file:
for Match regular expression "The Match Regular Expression function gives you more options for matching
strings but performs more slowly than the Match Pattern function....Use regular
expressions in this function to refine searches....
Characters to Find
Regular Expression
VOLTS
VOLTS
A plus sign or a minus sign
[+-]
A sequence of one or more digits
[0-9]+
Zero or more spaces
\s* or * (that is, a space followed by an asterisk)
One or more spaces, tabs, new lines, or carriage returns
[\t \r \n \s]+
One or more characters other than digits
[^0-9]+
The word Level only if it
appears at the beginning of the string
^Level
The word Volts only if it
appears at the end of the string
Volts$
The longest string within parentheses
The first string within parentheses but not containing any
parentheses within it
\([^()]*\)
A left bracket
A right bracket
cat, cag, cot, cog, dat, dag, dot, and dag
[cd][ao][tg]
cat or dog
cat|dog
dog, cat
dog, cat cat dog,cat
cat cat dog, and so on
((cat )*dog)
One or more of the letter a
followed by a space and the same number of the letter a, that is, a a, aa aa, aaa aaa, and so
on
(a+) \1
For Match Pattern "This function is similar to the Search and Replace
Pattern VI. The Match Pattern function gives you fewer options for matching
strings but performs more quickly than the Match Regular Expression
function. For example, the Match Pattern function does not support the
parenthesis or vertical bar (|) characters.
Characters to Find
Regular Expression
VOLTS
VOLTS
All uppercase and lowercase versions of volts, that is, VOLTS, Volts, volts, and so on
[Vv][Oo][Ll][Tt][Ss]
A space, a plus sign, or a minus sign
[+-]
A sequence of one or more digits
[0-9]+
Zero or more spaces
\s* or * (that is, a space followed by an asterisk)
One or more spaces, tabs, new lines, or carriage returns
[\t \r \n \s]+
One or more characters other than digits
[~0-9]+
The word Level only if it begins
at the offset position in the string
^Level
The word Volts only if it
appears at the end of the string
Volts$
The longest string within parentheses
The longest string within parentheses but not containing any
parentheses within it
([~()]*)
A left bracket
A right bracket
cat, dog, cot, dot, cog, and so on.
[cd][ao][tg]
Frustrating- but still managable.
Jeff -
Hi All,
What should be the regular expression for string MT940_UB_*.txt and MT940_MB_*.txt to be used as filename inSFTP sender channel in PI 7.31 ??
If any one has any idea on this please let me know.
Thanks
NehaHi All,
None of the file names suggested is working.
I have tried using - MT940_MB_*\.txt , MT940_MB_*.*txt , MT940*.txt
None of them is able to pick this filename - MT940_MB_20142204060823_1.txt
Currently I am using generic regular expression which picks all .txt files. - ([^\s]+(\.(txt))$)
Let me know ur suggestion on this.
Thanks
Neha Verma -
Using regular expressions for validation in i18n
Can we use regular expressions for validation of inputs in a java application taking care of i18N aspects too. Zip code for different locales are different. Can we use regular expressions to validate zipcode inputs from different locales
hi,
For that shall i have to create individual patterns for matching the inputs from different locales or a single pattern will do in the case of validating phone nos. around the world, zip codes etc. In case different patterns are required, programmer should have a konwledge of difference in patters for different locales.
regards
sdas -
Regular Expression For Dreamweaver
I still haven't had the time to really become a professional when it comes to regular expressions, and sadly I am in need of one an finding it difficult to wrap my head around.
In a text file I have hundreds of instances like the following:
{Click here to visit my website}{http://www.adobe.com/}
I need a regular expression for Dreamweaver that I can run within the "Find and Replace" window to switch the order of the above elements to:
{http://www.adobe.com/}{Click here to visit my website}
Can anyone provide some guidance? I'm coming up short due to my lack of experience with regular expressions.
Thank you in advance!So you have a string that starts { and goes until the first }. Then you have another string exactly the same. And you want to swap them. I'm not making any assumption that the second one has to look like a URL (that's a whole other minefield, but perhaps you could do something simple like it must start with http).
You don't specify how your text file is divided up, have you got this as a complete line to itself, or is it just a huge block of text? Preferably as individual lines.
I don't have Dreamweaver, but this worked for me in Notepad++
Find: ^{(.*?)}{(.*?)}$
Replace with: {\2}{\1}
My file looked like this:
{Click here to visit my website}{http://www.adobe.com/}
{some other site}{http://www.example.com/foo}
And doing a Replace All ended up like this:
{http://www.adobe.com/}{Click here to visit my website}
{http://www.example.com/foo}{some other site} -
Regular Expression for filename
I want to read XML files,If the filename starts with an alphabet.
Can anybody tell the regular expression for the same.
Regards
V Kumar
Message was edited by:
user640551thanks dhrmendra,
i got the solution and correct expression is "[a-zA-z].\*.xml"
regards
V Kumar -
Regular Expression for IPAddress
Hello members.....
I am a new member to this forum
I am in need of the Regular Expression for IPAddress...
"[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"....is the expression i wrote..But it is taking 0.0.0.0 as a valid IPAddress. (0.0.0.0 is not a valid IPAddress)
Please reply....awaiting
RajeshwarI am in need of the Regular Expression for
IPAddress...
"[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"
....is the expression i wrote..But it is taking
0.0.0.0 as a valid IPAddress. (0.0.0.0 is not a valid
IPAddress)Your regex matches "999.999.999.999", which (of course) isn't a vaild IP address as well.
This one is closer, but still allows 0.0.0.0:
\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\bBut why not roll your own method which checks an IP address? -
What is regular expression for cheking a set operation
I want a regular expression for checking the syntax of the set operation given as input
ex:
the input should be
[1,2,3]+[2,3] or [1,2]-[2] or [1,2,3]*[1,2]
is should check the square bracket and the operator between two set operandsI think you should code that from scratch. When you validate input, you usually want to tell the user what they did wrong, but a regex will only tell you whether it matches or not.
-
Hello Everybody,
Can someone tell me how to do the F4 for the file which is to be loaded from the presentation server,like v have for UPLOAD Function Module.
I have a Parameter for the file path in the selection,I want to know how do v take the file path by searching thru F4??
Thanks,
Anushka.Hi Anushka,
refer sample code:
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : rb_pc RADIOBUTTON GROUP r1 DEFAULT 'X'
USER-COMMAND ucomm, "For Presen
p_f1 LIKE rlgrap-filename
MODIF ID rb1, "Input File
rb_srv RADIOBUTTON GROUP r1,
"For Application
p_f2 LIKE rlgrap-filename
MODIF ID rb2,
"Input File
p_direct TYPE char128 MODIF ID abc DEFAULT c_path
"File Directory
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-020.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_f1.
*-- Browse Presentation Server
PERFORM f1000_browse_presentation_file.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_f2.
*-- Browse Application Server
PERFORM f1001_browse_appl_file.
*& Form f1000_browse_presentation_file
Pick up the file path in the presentation server
FORM f1000_browse_presentation_file .
CONSTANTS: lcl_path TYPE char20 VALUE 'C:\'.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = lcl_path
mask = c_mask "',.,..'
mode = c_mode
title = text-006
IMPORTING
filename = p_f1
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
flg_pre = c_x.
ENDIF.
ENDFORM. " f1000_browse_presentation_file
*& Form f1001_browse_appl_file
Pick up the file path in the application server
FORM f1001_browse_appl_file .
DATA: lcl_directory TYPE char128.
lcl_directory = p_direct.
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = lcl_directory
filemask = c_mask
IMPORTING
serverfile = p_f2
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e000(zmm) WITH text-039.
flg_app = 'X'.
ENDIF.
ENDFORM. " f1001_browse_appl_file
Reward points if this Helps.
Manish -
Regular Expression for a Person's Name
Hi,
I am using the org.apache.regexp package and trying to find the regular expression for a person's name. It allows only the alphabetic string.
I tried [a-zA-Z]+. But this also accepts the thing like "BUSH88", which is not what I want...
Can anybody help me figure this out?
Thanks in advance,
TongHi,
I am using the org.apache.regexp package and trying to
find the regular expression for a person's name. It
allows only the alphabetic string.
I tried [a-zA-Z]+. But this also accepts the thing
like "BUSH88", which is not what I want...
Can anybody help me figure this out?
Thanks in advance,
Tongtry this:
^[a-zA-Z]+$
the ^ represents the start of the String and the $ represents the end.
So the expression is saying: "between the beginning and the end of the String there will only be alphbetical characters"
Maybe you are looking for
-
Several errors lead to an unsuccesfully termination of instalation (3.0.1)
+ Versions o apex 3.0.1 o Oracle 9.2.0.6.0 + Several compilation errors during the instalation make this process to finish without succes. + The first error is this one: ...wwv_flow_sw_parser Warning: Package created with compilation errors. + Trying
-
Serial No in BAPI_GOODSMVT_CREATE
Hi All, I m developing a Y transaction for GR using Barcode. For that I m using a BAPI 'BAPI_GOODSMVT_CREATE' to post the data. Our requirement for serialized material is to maintain serial nos manually. In BAPI, for Serialized material, I maintain a
-
When exporting: Error -2014 "the movie contains an incorrect duration"
My end goal is to be able to edit .FLV files in iMovie, so I need to convert them to a usable format. I already have QT Pro, so it's the first thing I tried. I have Perian, so the .FLV files play with no issues, but when I try to export them to somet
-
Error when importing spml2.xml
Hi, I'm trying to configure SPML2. Currently it's not configured, i get error: javax.servlet.ServletException: There is no Configuration object named 'SPML2'. The SPML 2.0 interface has not been configured. when trying to use openspml toolkit. When I
-
Copying shapes to new states?
I have a rectangle on a layer and I want to create a simple rollover so I create a new state and select the shape and choose to distribute it to states. However, it does not seem to be copying it to the 2nd state? How do you do this?