Hello,
I am relatively new to matchers. I am toying around with hamcrest in combination with JUnit and I kinda like it.
Is there a way, to state that one of multiple choices is correct?
Something like
assertThat( result, is( either( 1, or( 2, or( 3 ) ) ) ) ) //does not work in hamcrest
The method I am testing returns one element of...
I am trying to find data within a HTML document. I don't need a full blown parser as it is just the data between one tag.
But, I want to detect the 'select' tag and the data in between.
return Pattern.compile(pattern,
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE |
Pattern.DOTALL);
/// E...
I have a Java program that does some String matching. I'm looking for anything that matches \d+x\d+ in a String. This works, using the Pattern and Matcher classes. However, to parse the String parts I have found, I have to manually parse the String I get from the Matcher.find() and Matcher.group(). How can I tell the Pattern I'm looking ...
Consider this code:
import java.util.regex.*;
public class Pattern3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Pattern p = Pattern.compile("Our"); //line 1
Matcher m = p.matcher("Our mom and Our dad"); //line ...
Possible duplicate: http://stackoverflow.com/questions/299942/regex-matching-html-tags-and-extracting-text
I need to get the text between the html tag like <p></p> or whatever. My pattern is this
Pattern pText = Pattern.compile(">([^>|^<]*?)<");
Anyone knows some better pattern, because this one its not very usefull. I need it to...
I have been banging my head against this for some time now:
I want to capture all [a-z]+[0-9]? character sequences excluding strings such as sin|cos|tan etc.
So having done my regex homework the following regex should work:
(?:(?!(sin|cos|tan)))\b[a-z]+[0-9]?
As you see I am using negative lookahead along with alternation - the \b aft...
Does any matcher libraries exist for .net?
I am talking about a library like the hamcrest library for java...
...
So I've been using EasyMock's class extension for a while now. All of a sudden I'm getting this exception, but only when I run the entire test suite:
java.lang.IllegalStateException: 0 matchers expected, 1 recorded.
at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:42)
at org.easymock.internal.Exp...
codes = new Vector<String>();
titles = new Vector<String>();
urls = new Vector<String>();
lecturers = new Vector<String>();
while (m.find()) {
String courseCode = m.group(1);
String courseTitle = m.group(2);
String courseURL = url;
String lecturerName = m.group(4);
codes.add(courseCode);
titles.add(courseTitl...
I have this code to
public static String ProcessTemplateInput(String input, int count) {
Pattern pattern = Pattern.compile("\\{([^\\}]+)\\}");
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
String newelem=SelectRandomFromTemplate(matcher.group(1), count);
}
return ...
Can anyone explain:
Why the two patterns used below give different results? (answered below)
Why the 2nd example gives a group count of 1 but says the start
and end of group 1 is -1?
public void testGroups() throws Exception
{
String TEST_STRING = "After Yes is group 1 End";
{
Pattern p;
Matcher m;
String pattern="(?:Y...
I am trying to use a simple split to break up the following string: 00-00000
My expression is: ^([0-9][0-9])(-)([0-9])([0-9])([0-9])([0-9])([0-9])
And my usage is:
String s = "00-00000";
String pattern = "^([0-9][0-9])(-)([0-9])([0-9])([0-9])([0-9])([0-9])";
String[] parts = s.split(pattern);
If I play around with the Pattern and ...
Hello,
I have following regex (abc|def)( ?(\\d+|(?:(?!\\1)[a-z])+)?)* with matches perfectly the subject abc123 456.
Now I want to get all parts abc, 123 and 456.
I use following code:
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(subject);
while(m.find())
{
System.out.println(m.group());
}
...
I want a regular expression that can match
<FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT> or
<LI><FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT></LI> and it should not be greedy
...
What is the regular expression that can match the following 2 strings.
Hi<Dog>Hi and <Dog> in a given text.
Update:
What regex will match this one?
If you access the web site click the link below:
matches only till the first
...
Hi all,
I have a string as follows:
TEST|A||B|C|**""**|D|""|||||\r\n
TEST|Z||V|P|**""**|Y||||||||\r\n
I need to make the content between 5th and 6th occurence of | to blank if the content is "".
So the desired output is
TEST|A||B|C||D|""|||||\r\n
TEST|Z||V|P||Y||||||||\r\n
So I am using matcher/pattern and matcher.replaceFirst() ...
Hi All,
my question is related to Regular Expressions in Java, and in particular, multiple matches for a given search pattern. All of the info i need to get is on 1 line and it contains an alias (e.g. SA) which maps to an IP address. Each one is separated by a comma. I need to extract each one.
SA "239.255.252.1", SB "239.255.252.2...
I am using a while(matcher.find()) to loop through all of the matches of a Pattern. For each instance or match of that pattern it finds, I want to replace matcher.group(3) with some new text. This text will be different for each one so I am using matcher.appendReplacement() to rebuild the original string with the new changes as it goes...
I am not sure if this is possible to do, but I need a way to replace a value of a numbered group specified in the my regex expression with a string declared dynamically at runtime, once a match has been made.
Given a simple case, something like...
(/)?([A-Za-z0-9])?(/)?$
I would want to be able to plugin a replacement for group 2.
I...