I need a Regex that will match a java method declaration. I have come up with one that will match a method declaration, but it requires the opening bracket of the ... |
I am writing a Java utility which helps me to generate loads of data for performance testing. It would be really cool to be able to specify a regex for ... |
The question pretty much sums it up. Just want to run a regular expression match on a string in J2ME.
|
I am trying to match multiple CSS style code blocks in a HTML document. This code will match the first one but won't match the second. What code would ... |
I've been struggling with doing some relatively straightforward regular expression matching in Java 1.4.2. I'm much more comfortable with the Perl way of doing things. Here's what's going on:
I ... |
This question got me thinking in a regex for matching javadoc comments that include some specified text.
For example, finding all javadoc fragments that include @deprecated:
/**
* Method1
* .....
* @deprecated
* @return
*/
I manage ... |
I am trying to use the cscope-indexer script. But I want to know how to change the following to include *.mm and *.java files?
egrep -i '\.([chly](xx|pp)*|cc|hh)$' | \
sed -e ...
|
|
So I have an IP address as a string.
I have this regex (\d{1-3})\.(\d{1-3})\.(\d{1-3})\.(\d{1-3})
How do I print the matching groups?
Thanks!
|
I'm using replaceAll() on a string to replace any letter with "[two letters]". So xxxaxxx to xxx[ab]xxx. I don't want the ones that have already been replaced to be done again ... |
I have a few regular expressions which are run against very long strings. However, the only part of the string which concerns the RE is near the beginning. Most of the ... |
How can I find all substrings that match a regex in Java? (Similar to Regex.Matches in .Net)
|
I'm using regular expressions to try to match section blocks in an INI file. I'm using the recipe given in the book Regular Expressions Cookbook, but it doesn't ... |
String text = "[! hello ¡world ¡] otra cosa ¡]";
String pt = "\\[!(.*)¡\\]";
Matcher mc = Pattern.compile(pt).matcher(text);
while( mc.find() ){
System.out.println(mc.group(1));
}
This code prints hello ¡world ¡] otra cosa.
What would be ... |
I am writing Java code that has to distinguish regular expressions with more than one possible match from regular expressions that have only one possible match.
For example:
"abc." can have several matches ... |
I'm building a small Java library which has to match units in strings. For example, if I have "300000000 m/s^2", I want it to match against "m" and "s^2".
So far, I ... |
I had this regex in java that matched either an alphanumeric character or the tilde (~)
^([a-z0-9])+|~$
Now I have to add also the characters - and _ I've tried a few combinations, ... |
I'm trying the following segment to no avail:
public class test {
public static void main(String args[] ){
String password = "s8bgBQYPmUaNjkToXCJLAwAA";
...
|
I have some lines in a text file like this:
==Text==
I'm trying to match the start, using this:
line.matches("^==[^=]")
However, this returns false for every line... little help?
|
I'm writing a plugin for emacs to compile and run a java source file with one keystroke.
Now I would like to find out the name of the main class or if ... |
In my program, I have a string (obtained from an external library) which doesn't match any regular expression.
String content = // extract text from PDF
assertTrue(content.matches(".*")); // fails
assertTrue(content.contains("S P E C I ...
|
In Java is there a way to extract the value of an unknown subset of a string via a regex. For example in the following string "hello world 1234" I want ... |
I know that the following works but it is not that readable, is there any way to make it more readable in the code itself without the addition of a comment?
//Start ...
|
I'm trying to parse an HTTP GET request to determine if the url contains any of a number of file types. If it does, I want to capture the entire ... |
I'm trying to match a specific string out of a an HTML document and have this regex pattern to grab it:
Pattern somePattern = Pattern.compile("var json = ({\"r\":\"^d1\".*});");
However when I try to ... |
Regexp in Java
I want to make a regexp who do this
verify if a word is like [0-9A-Za-z][._-'][0-9A-Za-z]
example for valid words
A21a_c32
daA.da2
das'2
dsada
ASDA
12SA89
non valid words
dsa#da2
34$
Thanks
|
I trying to tokenize following snippets by types of numbers:
"(0-22) 222-33-44, 222-555-666, tel./.fax (111-222-333) 22-33-44 UK, TEL/faks: 000-333-444, fax: 333-444-555, tel: 555-666-888"
and
"tel: 555-666-888, tel./fax (111-222-333) 22-33-44 UK"
and
"fax (111-222-333) 22-33-44 UK, ...
|
public class PatternTest {
public static void main(String[] args) {
System.out.println("117_117_0009v0_172_5738_5740".matches("^([0-9_]+v._.)"));
}
}
This program prints "false". What?!
I am expecting to match the prefix of the string: "117_117_0009v0_1"
I ... |
I don't understand why with this regex the method returns false;
Pattern.matches("\\bi", "an is");
the character i is at a word boundary!
|
*strong text*I have a bunch of lines in a textfile and I want to match this ${ALPANUMERIC characters} and replace it with ${SAME ALPHANUMERIC characters plus _SOMETEXT(CONSTANT)}.
I've tried this expression ${(.+)} ... |
I'm parsing a relatively complex expression in Java using regexps + some manual parsing. What I'm doing right now is removing what I've already parsed from the string, so I have ... |
I have problems running the matches XPATH method:
@Test(groups = "regression")
@Parameters( { "baseUri", "locale" })
public void testShopping(String baseUri, String locale) throws Exception{
session().allowNativeXpath("false");
String shoppingLink ...
|
I'm having troubles to create a regular expression who checks if a file has the extention .TMP so the pattern should accept any string who's not equal to (a-z 0-9 or ... |
I'll preface this question by mentioning that while I'm far from a regular expressions guru, they are not completely foreign to me. Building a regular expression to search for a pattern ... |
I have a String "REC/LESS FEES/CODE/AU013423".
What could be the regEx expression to match "REC" and "AU013423" (anything that is not surrounded by slashes /)
I am using /^>*/, which works and matches ... |
This is the second part of a series of educational regex articles. It shows how lookaheads and nested references can be used to match the non-regular languge anbn. Nested ... |
I am trying to write a regular expression to match any string that satisfies the following criteria.
The string begins and ends with a matching pair of parentheses '(' ')'
There may be ... |
Couple of questions:
1) How to make the following regex which are based on search literal ^ work for the search literal |
search literal ^ based regex (which works fine, which is ... |
I need some help writing a regular expression that matches this:
- an opening square bracket OR number as first character
- a closing square bracket (if there was an opening square bracket) OR number ...
|
I need to parse through a file(built from a string) searching for occurences of a single or multiline text. Will this solution always work ? If not - how should I ... |
This is the (non-escaped) regex i'm using so far
\{<<"(\w+)">>, \[(<<"(\w+)">>,?)+\]\}.
To match this:
{<<"user_1">>, [<<"user_2">>,<<"user_3">>,<<"user_04">>]}.
And these are the groups I'm getting:
1: user_1
2: <<"user_04">>
3: user_04
Any thoughts on why it isn't giving the multiple users?
If ... |
I've got a regex but I'm not sure what the {1,} stands for. Full regex is next: ^.{1,}$.
|
I execute the following code:
public static void test() {
Pattern p = Pattern.compile("BIP[0-9]{4}E");
Matcher m = p.matcher("BIP1111EgjgjgjhgjhgjgjgjgjhgjBIP1234EfghfhfghfghfghBIP5555E");
System.out.println(m.matches());
while(m.find()) {
System.out.println(m.group());
}
}
What i cannot explain is when the code is ... |
/*
patString: it$
input: this is it
the output at 2 to the match operation at 1 is false, why?
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ...
|
Basically my question is this, why is:
String word = "unauthenticated";
word.matches("[a-z]");
returning false? (Developed in java1.6)
Every bit of documentation I've read suggests this should work, as well as \S, ^\s, and other ... |
I need to match when a string begins with number, then a dot follows, then one space and 1 or more upper case characters. The match must occur at the beginning ... |
Here is my example file :
lineone one
RUN lineone two
lineone three
RUN lineone four
I want to select all lines not starting with run, here is how I did it :
^([^RUN])
Is it possible to ... |
how do i return after the first match of regular expression? (does the Matcher.find() method do that? )
say I have a string "abcdefgeee". I want to ask the regex engine stop ... |
I created a regular expression bellow to do this. But it also matches comments like //This class blabla...
\\S*.*\\s*(class|interface|enum|@interface)\\s+.*
Would you help me come out a regular expression to match the java class/interface/etc.. ... |
I have a bunch of images with names such as nineDiamonds.gif and aceHearts.gif along with a "Card" class for playing card faces.
In the constructor, I want to pass a String of ... |
I am trying to make the following match, but it is not returning true as I would expect:
String attrs = "id|fullname|email|title";
String regex = "fullname|email";
return attrs.matches(regex);
Instead it returns false.
Why is this? I ... |
I am having String str = "$$\\frac{6}{8}$$"; I want to match for strings using starting with '$$' and ending with '$$'
How to write the regular expression for this?
|
What is the java regex to match the below pattern?
<anyString>.<5 or 10>.anyNumber.anyNumber
Here 5 and 10 are numbers.
|
Using Java regex pattern I want to match the & symbol. But it should not match &, < etc... (HTML encoding).
|
I need a regular expression that will match the file name of a ResourceBundle, which follows the format name_lo_CA_le.properties. It should only match bundles that have a locale portion in their ... |
My entering string can be in format TIM0.VW0 ( it always starts with TIM or CNT or ENC followed by numbers, then always point and at the end char or chars ... |
I'm performing query operations on a Lucene index with a RegexQuery. For example, I do a RegexQuery to obtain all documents containing a URL, using new RegexQuery(new Term("text", "https?://[^\\s]+") (I know, ... |
What is the best way to match fully qualified Java name.
Like java.lang.Reflect, java.util.ArrayList, org.hibernate.Hibernate
Thanks
|
I need regex for a line that starts with two characters followed by 2-4 digits or 2-4 digits followed by "-" and followed by 2-4 digits.
Examples:
Seems simple , but I got ... |
I'm trying to match a hyphen in all situations except when it is preceded by whitespace and proceeded by non-whitespace.
x-y //match
x - y //match
x- y //match
x -y ...
|
I want to match a regex of the following form
(hex_number) (anything) constant=(true or false)
anything can match any printable character or a space or tab. I am programming in java so I ... |
OK,
I don't know if it is possible to write this regex, so I am going to start by askign for help - so far I have had no success.
source string:
,convert(varchar(8000), ...
|
I have the following regex for capturing links in tags (the tags are given in a string without the angular brackets):
^a .*href=['\"]([^'\"]*)['\"].*
and I have the following string:
a href="/wiki/Hypertext_Transfer_Protocol" title="Hypertext Transfer Protocol"
And ... |
I would like to search a String for an entire match. In other words, if String s = "I am coding", and I type in that I am searching for ... |
What's the correct regex to match such set [1] [2] [3] [4] [23] - where numbers are inside the brackets. (I need to get the brackets though)
|
I need a regexp to get the whole exception name incl. dots from stacktrace and it's a whitespace before it.
Time: Sun Apr 10 20:36:57 CEST 2011
Message: java.lang.NullPointerException
at com.hello.World.Hi.initDB(bla.java:273)
... |
I have tests where I validate the output with a regex. When it fails it reports that output X did not match regex Y.
I would like to add some indication ... |
I want to match the following strings:
<a href="http://xyz">xyz</a>
<a href="https://xyz">xyz</a>
<a href="xyz">xyz</a>
and I tried to use the regex but failed:
<a href="((http://|https://|).+)">\1</a>
What is the correct solution to achieve this?
Thanks!
|
My program takes a string input from a user. If the input string matches the regular expression then it should be inserted into the arrayList.
I wrote that following. But, it does ... |
The regex String :
"[Ff][uU][Nn][Cc] "
Matches input:
"fUnC "
But not:
"func across( a, b )"
And I don't understand why...
I'm testing my expressions here:
http://www.regexplanet.com/simple/index.html
I figured out that I (dumbly) needed my ... |
How to construct a regex not to contain a set of strings within.
For this example, I want to validate the Address Line 1 text box so that it wont contain ... |
I've a trouble with regexp in such situation:
I need to extract (and replace) all dots from such construction:
any_symbols->white_space->x.(or xx. or Xx. or xX. or xy. or yy. etc.)->white_space->any_symbol_not_upper_case_and_not_a_digit
for example
1990 x. abcd ...
|
I'm trying to remember the correct notation for doing find-replace regex matches in Java.
Say I have the string
String s = "My name is ''Eric'' and ...
|
Hopefully a quick question. I'm trying to validate a double. Making sure it's positive to one decimal place.
Good Values: 0.1, 2.5, 100.1, 1, 54
Bad Values: -0.1, 1.123, 1.12, abc, 00012.1
So I've ... |
I think it's matching all control characters (not sure what "all" might be) but I can't be certain, nor can I find it in any documentation other than some musings in ... |
I would like to match the following
- com.my.company.moduleA.MyClassName
- com.my.company.moduleB.MyClassName
- com.my.company.anythingElse.MyClassName
but not the following
- com.my.company.core.MyClassName
My current simple regex pattern is :
Pattern PATTERN_MODULE_NAME = Pattern.compile("com\\.my\\.company\\.(.*?)\\..*")
Matcher matcher = PATTERN_MODULE_NAME.matcher(className);
if (matcher.matches()) {
// will return the ...
|
Why does this code throw a InputMismatchException ?
Scanner scanner = new Scanner("hello world");
System.out.println(scanner.next("hello\\s*world"));
The same regex matches in http://regexpal.com/ (with \s instead of \\s)
|
I need to generate, at run time, a regular expression that will match a range of numeric values.
For example: At run time I may discover that I need a regular expression ... |
I am having a problem with a generic regex that matches (sort of) a typical string of the form
... "field1" "field2" "field3" "field4" ...
What I want to do is, of course, ... |
I have looked through all kinds of Java REGEX information and have not found the answer I'm looking for:
How do I find all Strings that are between two values (abc and ... |
I can't find out why my regex does not match a line when using java's String.matches method - it does match using on online regex tester.
Here is the Java-Code: ... |
This feels like it should be an extremely simple thing to do with regex but I can't quite seem to figure it out.
I would like to write a regex which ... |
I have some code setup to remove extra spaces in between the words of a title
String formattedString = unformattedString.replaceAll(" +"," ");
My understanding of this type of regex is that it will ... |
I have these strings in an array and I want to iterate this array and find those who match (one line per match check).
The thing is, I can't find the right ... |
I'm trying to match a coordinate pair in a String using a Regex in Java. I explicitly want to exclude strings using negative lookahead.
to be matched:
558,228
558,228,
558,228,589
558,228,A,B,C
NOT to be matched:
558,228,<Text>
The Regex ^558,228(?!,<).* ... |
I have this code, but it does not seem to be working.
Pattern pattern=Pattern.compile("IMGURSESSION=([0-9a-zA-Z]*);");
Matcher matcher=pattern.matcher("IMGURSESSION=blahblah; path=/; domain=.imgur.com");
System.out.println(matcher.matches());
Would anyone know why?
|
I have an unlimited sequence of strings and numerous regular expressions ordered by priorities. For each string in a sequence I have to to find the first matching regular expression and ... |
I have a multiline XML blob in a Java String that I'd like to grep some values out of. I know that regexes and XML mix like crude oil and ... |
String.split(String regex) splits the string around a given regular expression and returns an String array. But I am interested in the regex matches and would like them to be returned as ... |
How do I combine ch..+ and ch..- in regexp effectively without having to scan separately?
And are we using matcher in the pattern?
My output code is like this:
ch01+
ch01-
ch02+
ch02-
...
|
In Java, how can you determine if a String matches a format string (ie: song%03d.mp3)?
In other words, how would you implement the following function?
/**
* @return true if formatted equals ...
|
I am trying to create a regular expression for the following rule.
RegEx: ([A-Z]|[0-9])[\\.a-zA-Z0-9_-]{0,}$
Rule: Combination of letters, hyphen and dash, also must contains upper case letter or number.
When I try the string ... |
Following this question it gives me just 1st match. I want to get all the matching into a string or a string array
This is my part of output from which ... |
Here is the input string:
#video:firstVideo.mp4#
#video:secondVideo.mp4 title:Title of second Video#
#video:thirdVideo.mp4#
I want to match all of the above lines (the title: attribute is optional). However, the Java RegEx below will only match the ... |
I used perl, unix and java regular expression lot of time, but I'm surprised in java about that:
"help".matches("^h")
is false!!
From java documentation:
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#matches(java.lang.String)
"true if, and ... |
Why does String.matches return true when two values are in [] brackets?
System.out.println("[one]".matches("(?i).*" + "[two]" + ".*"));
//Why does it return true? Shouldn't "[]" be treated as value?
System.out.println("one".matches("(?i).*" + "two" ...
|
Regex (?:[,\\. ]*(&|and) ?) is not matching ", and ". But when i change the matcher to (?:[,\\.] ?(&|and) ?) the pattern ", and " is getting matched. What is causing ... |
I want to write matching expression to read string between parentheses () from a big string. eg: the big string is:-
(something), (something2), (something3)
How can I write matching expression for this to ... |
I'm used to regular expressions from Perl. Does anybody know why this doesn't work (eg. "yea" isn't printed)?
if ("zip".matches("ip"))
System.out.println("yea");
Thank you.
|
I encountered an interesting issue about String's matches(RegExp) method.
assertTrue("33CCFF".matches("[0-9A-Za-z]{6}"));
assertTrue("CC33FF".matches("[0-9A-Za-z]{6}"));
assertTrue("CC3355".matches("[0-9A-Za-z]{6}"));
assertTrue("CC9955".matches("[0-9A-Za-z]{6}"));
assertTrue("CC3366".matches("[0-9A-Za-z]{6}"));
assertTrue("CC3965".matches("[0-9A-Za-z]{6}"));
assertTrue("CC1961".matches("[0-9A-Za-z]{6}"));
assertTrue("CC9999".matches("[0-9A-Za-z]{6}"));
assertTrue("??3966".matches("[0-9A-Za-z]{6}")); // failing
assertTrue("??9965".matches("[0-9A-Za-z]{6}")); // failing
assertTrue("??9966".matches("[0-9A-Za-z]{6}")); // failing
The last 3 assertion is failing unexpectedly. I couldn't find any reasons why this weird behavior ... |
I have the following entries in my log files:
09-22-11 12:35:09 1ms INFO ...erChangeSetListener:91 ...
|