Tagged Questions
0
votes
3answers
28 views
How to replace multiple words with space in a string using Java
I tried to replace a list of words from a give string with the following code.
String Sample = " he saw a cat running of that pat's mat ";
String regex = "'s | he | of | to | a | and | in | that";
...
0
votes
7answers
44 views
Replace the last occurrence of a string in another string
Let's say I have a string
string myWord="AAAAA";
I want to replace "AA" with "BB", but only the last occurrence, like so:
"AAABB"
Neither string.replace() nor string.replaceFirst() would do the ...
0
votes
1answer
26 views
Regex matches space between characters
I have this regex
(\((-?\d+.\d+\s?-?\d+.\d+,?)+\))*
that seems to be matching the space between characters at the very beginning of the string along with the parts that I would like to match.How ...
-1
votes
1answer
29 views
Regex expression for |abc-amount [on hold]
I want a regex for my output
|Term Loan-amount or |Bill Purchase / Discounting (Inland)-amount or |PARTNER_NAME-PAN
should accept only in this fashion.
-2
votes
1answer
34 views
regular expression matching for [ ]
I have a regex expression
[a-zA-Z- \d )( / . ]
which matches my requirements but i want it to match [] this brackets too.
It should match my output:
24301-Manufacture of man-made fibres [this class ...
0
votes
1answer
23 views
How do I extract variable data from a line of string with tags?
I'm trying to write Java code to go to a website, read the HTML code line-by-line, extract certain pieces of data, including an embedded URL to go to another website, and repeat the process 100 times. ...
0
votes
2answers
26 views
How to create a Patern for a date using a Scanner?
I have a .csv file with line like
30-11-2013 ;30-11-2013 ;SUMMARY ;0.0 ;200.0 ;2800.0 ;2800.0
31-12-2013 ;31-12-2013 ;SUMMARY ;0.0 ;200.0 ;3000.0 ;3000.0
02-01-2014 ;02-01-2014 ;TRANSF ;0.0 ;300.0 ...
0
votes
1answer
27 views
java.util.regex Validating Phone numbers
I am trying to validate a phone number input from a user(in my project). This is the method I created trying to validate it and also give them 3 tries to enter a valid format. However what ever I ...
1
vote
2answers
51 views
Java regex, find text inside
I need to find some string in text after keyword in inside brackets first occurrence.
This is the text example:
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor ...
0
votes
4answers
39 views
Remove special characters surrounded by white space
How can i remove special characters having white space on side.
String webcontent = "This is my string. i got this string from blabla.com."
When i use this regex
...
0
votes
0answers
41 views
How to Use this type of string data in Android?
I am working with a web service for my next android application. This web service returns me some data, which is in an escape sequence and in JSON format. I am not able to process it using Java in ...
-3
votes
3answers
38 views
regular expression for string “ a123ab-lift(admin-hat)” [on hold]
I want to know the regex which confirms to
a123ab-lift(admin-hat)
My string can contain alphabets, numbers and characters " ( " , " ) " , " - "
-3
votes
3answers
55 views
Java - making a regex that checks if some letters are in a string [on hold]
I am trying to make regex that will check if certain characters are in a string. For instance if I have the string "example" I want to be able to decide if the characters e, l and a are in the string. ...
0
votes
1answer
14 views
Largest Row and Column Java regex
Here is a program that determines the largest row and column on any given random array.
I am not sure what the last 3 lines of code are doing.
I know they are part of the regular expression but ...
0
votes
5answers
56 views
.replaceAll() method not working correctly
As a bit of background to the problem I load in a text file and then assign a phrase from that text file to become a randomPirateWord, I then change the letters into that text file to become **'s and ...
-2
votes
1answer
15 views
What is the Java equivalent of Perl’s regex with eval? [duplicate]
I know that the answer to my question is somewhere around here, but I just can’t find it anymore. I tried several searches like
java string replace execute code
java matcher replace execute code
...
2
votes
4answers
54 views
Regex Pattern matching for an URL
I have a method and input to that is an URL string. I would different types of URL (sample 5 URLs i have mentioned below)
String url1 = "http://domainName/contentid/controller_hscc.jsp?q=1" ;
String ...
0
votes
3answers
49 views
Regex doesnt work, how should it be formulated?
I Want to know if a String consists only of the same character except at the last index, it can be any other possible character except the character that's leading.
For Example: "FFFFFFFl" matches ...
0
votes
0answers
14 views
Apache Lucene index large files based on new lines [on hold]
Scenario
I want to be able to allow text search features that users can use to search through large log files (~10 GB) in the browser? The user will input a search query and they should get back all ...
0
votes
1answer
33 views
HTML content to a string with regular expressions
I need to compose an email body and have user name password atributes to be added of every user to it. For now i have the html content in a string and im trying to have string formatter to replace the ...
0
votes
1answer
30 views
Modifying xml via regex in java
I have the following XML String:
<asd1:content></asd1:content>
The namespace prefix asd1 could be different at different places in the XML file.
I want to modify it to :
...
1
vote
4answers
39 views
Group Matching Regex fails in Java
Why does this regex pattern fail to match the groups in Java. When I run the same example with in a bash shell with echo and sed it works.
String s = "Match foo and bar and baz";
//Pattern p = ...
0
votes
2answers
21 views
String Message Staring with bullet-in needs to in the nextLine
I had string message,which contains message like below.
Here im trying to spilt the message when the line starts with number followed by .(full stop)
String str="1. Hi this is test 2. this is also ...
-1
votes
4answers
42 views
get the pattern before a given word
below is my text :
12,7 C84921797-6 Provisoirement, 848,80 smth
i want to extract the value 848,80 with the float pattern : [-+]?[0-9]*\\,?[0-9]+
but the code i am using extracts only the first ...
0
votes
1answer
48 views
Regex not matching what I want [on hold]
Every time I submit a html form with the request "Password" I get a return telling me it doesn't match the password complexity rules. My validation doesn't seem to work. If anyone can shed any light ...
0
votes
2answers
40 views
Extracting Strings within messages which contains concatanation characters
I'm trying to extract messages from following type of strings,
Error_Message('The value 1,2 and 3 that you have entered is invalid.');
using the following regular expression,
...
0
votes
3answers
42 views
RegEx to match a string between a set of words
I am trying to match a group of words between two words in a String. I will be using Java RegEx.
Input Text
The clever fox JUMPED OVER the big dog and ran away.
Expected Output
the big
RegEx ...
0
votes
1answer
44 views
Display characters other than alphabets using regular expression
I want to have this functionality in the server side using java.util.regex.Pattern and java.util.regex.Matcher.
"cdAbb#2547dbsbz78678".match(/[^a-zA-Z]+/g).join('');
0
votes
0answers
27 views
How to compare the Xml file containing list of regular Expression with another XML in java?
EX:
I want to Compare this two file and filter out the common things...
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;) OR 1=1 --
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;) AND ...
-2
votes
2answers
62 views
regex for even no. of single quotes
I am trying to find 'AND' followed by even no. of single(') quotes and replace it with 'OR', I am trying it in java using regex but no luck so far
e.g. company='sam"'"s AND joseph"'"s' AND ...
-1
votes
3answers
32 views
Java Regex needed
I need regex that will fail only for below patterns and pass for everything else.
RXXXXXXXXXX (X are digits)
XXX.XXX.XXX.XXX (IP address)
I have basic knowledge of regex but not sure how to ...
0
votes
2answers
28 views
Why is there a PatternSyntax Excpetion for the following program?
I am getting a Pattern Syntax Exception for the following program. I have escaped the backslashes by using "\\", but there is a still an exception saying:
Exception in thread "main" ...
0
votes
3answers
47 views
Regex to get rid of content after the first “>”
Regex to get rid of the content after first ">" in the string below. And putting whatever is there after the first ">" in another string .
eg:
String input = <img alt="" ...
-3
votes
1answer
35 views
HackerRank Tweets Concern [on hold]
I am working on HackerRank problems alongside project euler to help me improve in java. I have a question about the HackerRank tweets problem. The problem is described here: ...
0
votes
3answers
68 views
Regex to seperate the lines of the file
Lesson no 1
lesson name: Jack and Jill went to America
lesson contents: some XXXXX XXXXX contents
lesson Description: jack and jill lesson description
Lesson no 2
lesson name: Lorem ipsum ...
0
votes
3answers
23 views
regex: tokenizing <opening><scotch-game><fried-liver-attack>
How can I get individual tokens of the the <opening><scotch-game><fried-liver-attack> string using regex. So the output should be 3 following strings:
opening
scotch-game
...
4
votes
2answers
39 views
Regular expressions optional items
If I have this regular expression
print_first = print_first.replace(/ T(op Choice)?/gi, "<span class='top_choice'> Top Choice</span>");
Shouldn't this match these strings: T, ...
0
votes
4answers
44 views
Insert character before specific character Java
I have been taking a look at the regular expressions and how to use it in Java for the problem I have to solve. I have to insert a \ before every ". This is what I have:
public class TestExpressions ...
0
votes
3answers
33 views
Regex for instances in STEP-files?
I have to parse some STEP-files (ISO-10303-21) from different CAD-Systems and they are always structured differently. This are the forms that might appear:
#95=STYLED_ITEM('',(#94),#92);
#12 = ...
0
votes
3answers
40 views
groupCount() in java.util.regex.Matcher always returns 0
I've trying to count how many matching patterns are there in a string. I'm new to using java.util.regex and I was planning on using matcher.groupCount() to get the number of matching groups. Since ...
3
votes
3answers
58 views
Removing a large space from a text in Java
I am trying to remove a big whitespace and retain the CR and LF character in a String. This string is generated by Lotus Domino API. This is basically an eml file converted to text by Lotus API.
When ...
0
votes
3answers
61 views
What is Java Regex to check if a String is a chain of numbers delimited by “_” (java)?
I want to check if a String is a chain of numbers delimited by "_":
Examples:
200_121_545 : return true;
455 : return true; // it doesn't need _ to be valid, a number is ok
ff_78 ...
-5
votes
1answer
50 views
How to strip the package name from a fully qualified class name [on hold]
How to match a fully qualified class name like com.mycompany.models.Friend using regex and strip away the package name so the result would be Friend for the example given?
1
vote
4answers
46 views
Regex in Java with multiple condition to extract arithmetic operator
I am new to regular expression syntax, after one whole day digging on the google, still can't find a good regex in java to extract the thing I want from a string...
for example:I have a
stringA = ...
0
votes
3answers
75 views
Java String tokens
I have a string line
String user_name = "id=123 user=aron name=aron app=application";
and I have a list that contains: {user,cuser,suser}
And i have to get the user part from string. So i have ...
0
votes
2answers
48 views
Word boundary in regular expression
I am using the following regular expression:
if (input.matches("^[\\d\\s()\bAND\b\bOR\b.]+$")) {
// do something
}
My goal is to validate only numbers (int and decimal), spaces, ( ), dot, AND, ...
0
votes
1answer
33 views
java.lang.illegalargumentexception - thrown by HttpURLConnection getHeaderFieldKey() method, host = null
I'm trying to build a simple linkchecker application. I extract all href attributes from a webpage, and output to a file. I then check what I have parsed against a regex to check for valid URLs, and ...
0
votes
2answers
25 views
Extract value from string using regex that has a pattern
Want to return a extracted value from string which matches a particular pattern.
Fot eg: i want to extract "hotmail" from String s = "[email protected]"
import java.util.*;
import ...
1
vote
1answer
13 views
Check for underscore wrapped any valid Windows filename characters except underscore and csv extension
I'm still very new to regex, so I think I can determine whether a string ends with a case-insensitive .csv:
(\\.(?i)(csv))
However, I do not know how to check that everything before that is at ...
3
votes
3answers
55 views
Java RegEx for parsing the quoted arguments
Need a Java regex pattern for the following scenario:
Case 1:
Input string:
"a"
Matches:
a
Case 2:
Input string:
"a b"
Matches:
a b
Case 3:
Input string:
"aA Bb" cCc 123 4 5 6 ...