Find out a given word in a String using Regex in java [closed]
up vote
-2
down vote
favorite
Given a String,
Using regex in java or java code i have to find out Electors name from the given String :
"K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘"
Like for the given String the output should be : Moleslwar Moreshva Tuwal
Can't hardcode anything as the String response changes everytime.
Please help:)
java regex regex-group
closed as too broad by Wiktor Stribiżew, ochi, Owen Pauling, greg-449, The fourth bird Nov 22 at 11:20
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-2
down vote
favorite
Given a String,
Using regex in java or java code i have to find out Electors name from the given String :
"K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘"
Like for the given String the output should be : Moleslwar Moreshva Tuwal
Can't hardcode anything as the String response changes everytime.
Please help:)
java regex regex-group
closed as too broad by Wiktor Stribiżew, ochi, Owen Pauling, greg-449, The fourth bird Nov 22 at 11:20
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
How does the string change, and what part of the string remains the same? Do you have a code example of what you already tried?
– Stephan Hogenboom
Nov 22 at 9:01
This string is generated by getting characters from an image.So, it doesn't remain the same. The String "Electors name" is constant.
– ankur43
Nov 22 at 9:07
Then how do you knowmam-a #02.....
isn't part of the name?
– Jai
Nov 22 at 9:16
beacuse i also have the document from which this string is retrieved :D
– ankur43
Nov 22 at 9:23
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
Given a String,
Using regex in java or java code i have to find out Electors name from the given String :
"K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘"
Like for the given String the output should be : Moleslwar Moreshva Tuwal
Can't hardcode anything as the String response changes everytime.
Please help:)
java regex regex-group
Given a String,
Using regex in java or java code i have to find out Electors name from the given String :
"K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘"
Like for the given String the output should be : Moleslwar Moreshva Tuwal
Can't hardcode anything as the String response changes everytime.
Please help:)
java regex regex-group
java regex regex-group
asked Nov 22 at 8:55
ankur43
65
65
closed as too broad by Wiktor Stribiżew, ochi, Owen Pauling, greg-449, The fourth bird Nov 22 at 11:20
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by Wiktor Stribiżew, ochi, Owen Pauling, greg-449, The fourth bird Nov 22 at 11:20
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
How does the string change, and what part of the string remains the same? Do you have a code example of what you already tried?
– Stephan Hogenboom
Nov 22 at 9:01
This string is generated by getting characters from an image.So, it doesn't remain the same. The String "Electors name" is constant.
– ankur43
Nov 22 at 9:07
Then how do you knowmam-a #02.....
isn't part of the name?
– Jai
Nov 22 at 9:16
beacuse i also have the document from which this string is retrieved :D
– ankur43
Nov 22 at 9:23
add a comment |
How does the string change, and what part of the string remains the same? Do you have a code example of what you already tried?
– Stephan Hogenboom
Nov 22 at 9:01
This string is generated by getting characters from an image.So, it doesn't remain the same. The String "Electors name" is constant.
– ankur43
Nov 22 at 9:07
Then how do you knowmam-a #02.....
isn't part of the name?
– Jai
Nov 22 at 9:16
beacuse i also have the document from which this string is retrieved :D
– ankur43
Nov 22 at 9:23
How does the string change, and what part of the string remains the same? Do you have a code example of what you already tried?
– Stephan Hogenboom
Nov 22 at 9:01
How does the string change, and what part of the string remains the same? Do you have a code example of what you already tried?
– Stephan Hogenboom
Nov 22 at 9:01
This string is generated by getting characters from an image.So, it doesn't remain the same. The String "Electors name" is constant.
– ankur43
Nov 22 at 9:07
This string is generated by getting characters from an image.So, it doesn't remain the same. The String "Electors name" is constant.
– ankur43
Nov 22 at 9:07
Then how do you know
mam-a #02.....
isn't part of the name?– Jai
Nov 22 at 9:16
Then how do you know
mam-a #02.....
isn't part of the name?– Jai
Nov 22 at 9:16
beacuse i also have the document from which this string is retrieved :D
– ankur43
Nov 22 at 9:23
beacuse i also have the document from which this string is retrieved :D
– ankur43
Nov 22 at 9:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
There is no name end delimiter hence will have to assume the full name needs to be captured from the line where Electors name
is present and the next line only. And once it is captured, replace unwanted character with a space.
Here is the java code that parses the name for you,
public static void main(String args) {
String s = "K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘";
Pattern p = Pattern.compile("Electors name\s*;\s*([\w; ]+\n\w+)");
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group(1).replaceAll(";\n", " "));
} else {
System.out.println("Didn't match");
}
}
This prints following output,
Moleslwar Moreshva Tuwal
Thanks a lot :)
– ankur43
Nov 22 at 10:13
Could you please help me to get out the name when the String is : ": 43 i Hit : GD | HRT Pav amar h Ted a3 ! ZMY1960756 : y | A : for ib Wags v, | EKO fadias =r amy; fra Electors Name : ANKIT | Rar #1 am: gob aw Father's Name: MURARI LAL | AT 1 Sex ' i I Male | 3 : 11/03/1990 S sFafafa/ oos ;"
– ankur43
Nov 22 at 10:14
The given String should display "ANKIT" as output
– ankur43
Nov 22 at 10:17
Your this string looks better than earlier in your post, because here at least I see a delimiter which is|
. You can use this regexElectors Name\s*:\s*([\w ]+)\s*\|
– Pushpesh Kumar Rajwanshi
Nov 22 at 10:20
1
Done!! Thanks!!!
– ankur43
Nov 22 at 11:22
|
show 10 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
There is no name end delimiter hence will have to assume the full name needs to be captured from the line where Electors name
is present and the next line only. And once it is captured, replace unwanted character with a space.
Here is the java code that parses the name for you,
public static void main(String args) {
String s = "K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘";
Pattern p = Pattern.compile("Electors name\s*;\s*([\w; ]+\n\w+)");
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group(1).replaceAll(";\n", " "));
} else {
System.out.println("Didn't match");
}
}
This prints following output,
Moleslwar Moreshva Tuwal
Thanks a lot :)
– ankur43
Nov 22 at 10:13
Could you please help me to get out the name when the String is : ": 43 i Hit : GD | HRT Pav amar h Ted a3 ! ZMY1960756 : y | A : for ib Wags v, | EKO fadias =r amy; fra Electors Name : ANKIT | Rar #1 am: gob aw Father's Name: MURARI LAL | AT 1 Sex ' i I Male | 3 : 11/03/1990 S sFafafa/ oos ;"
– ankur43
Nov 22 at 10:14
The given String should display "ANKIT" as output
– ankur43
Nov 22 at 10:17
Your this string looks better than earlier in your post, because here at least I see a delimiter which is|
. You can use this regexElectors Name\s*:\s*([\w ]+)\s*\|
– Pushpesh Kumar Rajwanshi
Nov 22 at 10:20
1
Done!! Thanks!!!
– ankur43
Nov 22 at 11:22
|
show 10 more comments
up vote
0
down vote
accepted
There is no name end delimiter hence will have to assume the full name needs to be captured from the line where Electors name
is present and the next line only. And once it is captured, replace unwanted character with a space.
Here is the java code that parses the name for you,
public static void main(String args) {
String s = "K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘";
Pattern p = Pattern.compile("Electors name\s*;\s*([\w; ]+\n\w+)");
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group(1).replaceAll(";\n", " "));
} else {
System.out.println("Didn't match");
}
}
This prints following output,
Moleslwar Moreshva Tuwal
Thanks a lot :)
– ankur43
Nov 22 at 10:13
Could you please help me to get out the name when the String is : ": 43 i Hit : GD | HRT Pav amar h Ted a3 ! ZMY1960756 : y | A : for ib Wags v, | EKO fadias =r amy; fra Electors Name : ANKIT | Rar #1 am: gob aw Father's Name: MURARI LAL | AT 1 Sex ' i I Male | 3 : 11/03/1990 S sFafafa/ oos ;"
– ankur43
Nov 22 at 10:14
The given String should display "ANKIT" as output
– ankur43
Nov 22 at 10:17
Your this string looks better than earlier in your post, because here at least I see a delimiter which is|
. You can use this regexElectors Name\s*:\s*([\w ]+)\s*\|
– Pushpesh Kumar Rajwanshi
Nov 22 at 10:20
1
Done!! Thanks!!!
– ankur43
Nov 22 at 11:22
|
show 10 more comments
up vote
0
down vote
accepted
up vote
0
down vote
accepted
There is no name end delimiter hence will have to assume the full name needs to be captured from the line where Electors name
is present and the next line only. And once it is captured, replace unwanted character with a space.
Here is the java code that parses the name for you,
public static void main(String args) {
String s = "K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘";
Pattern p = Pattern.compile("Electors name\s*;\s*([\w; ]+\n\w+)");
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group(1).replaceAll(";\n", " "));
} else {
System.out.println("Didn't match");
}
}
This prints following output,
Moleslwar Moreshva Tuwal
There is no name end delimiter hence will have to assume the full name needs to be captured from the line where Electors name
is present and the next line only. And once it is captured, replace unwanted character with a space.
Here is the java code that parses the name for you,
public static void main(String args) {
String s = "K ~n" +
"m W swimn" +
"sfiaruqsrn" +
"wvnn 021m: r’ i" W' _ ~n" +
"_ 4'“; x ‘ Dn" +
"W ma ¢ “ii-a? “Rm qwfln" +
"Electors name ; Moleslwar Moreshva;n" +
"Tuwaln" +
"mam-a #02,qu _n" +
"Fn" +
"Fm“ Name : Momma! Tuppal In" +
"‘ en" +
"Pam sq» : w! MALE 'n" +
"“WW/Dale m mm ; XX/xxnsae _‘";
Pattern p = Pattern.compile("Electors name\s*;\s*([\w; ]+\n\w+)");
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group(1).replaceAll(";\n", " "));
} else {
System.out.println("Didn't match");
}
}
This prints following output,
Moleslwar Moreshva Tuwal
answered Nov 22 at 9:19
Pushpesh Kumar Rajwanshi
3,8151825
3,8151825
Thanks a lot :)
– ankur43
Nov 22 at 10:13
Could you please help me to get out the name when the String is : ": 43 i Hit : GD | HRT Pav amar h Ted a3 ! ZMY1960756 : y | A : for ib Wags v, | EKO fadias =r amy; fra Electors Name : ANKIT | Rar #1 am: gob aw Father's Name: MURARI LAL | AT 1 Sex ' i I Male | 3 : 11/03/1990 S sFafafa/ oos ;"
– ankur43
Nov 22 at 10:14
The given String should display "ANKIT" as output
– ankur43
Nov 22 at 10:17
Your this string looks better than earlier in your post, because here at least I see a delimiter which is|
. You can use this regexElectors Name\s*:\s*([\w ]+)\s*\|
– Pushpesh Kumar Rajwanshi
Nov 22 at 10:20
1
Done!! Thanks!!!
– ankur43
Nov 22 at 11:22
|
show 10 more comments
Thanks a lot :)
– ankur43
Nov 22 at 10:13
Could you please help me to get out the name when the String is : ": 43 i Hit : GD | HRT Pav amar h Ted a3 ! ZMY1960756 : y | A : for ib Wags v, | EKO fadias =r amy; fra Electors Name : ANKIT | Rar #1 am: gob aw Father's Name: MURARI LAL | AT 1 Sex ' i I Male | 3 : 11/03/1990 S sFafafa/ oos ;"
– ankur43
Nov 22 at 10:14
The given String should display "ANKIT" as output
– ankur43
Nov 22 at 10:17
Your this string looks better than earlier in your post, because here at least I see a delimiter which is|
. You can use this regexElectors Name\s*:\s*([\w ]+)\s*\|
– Pushpesh Kumar Rajwanshi
Nov 22 at 10:20
1
Done!! Thanks!!!
– ankur43
Nov 22 at 11:22
Thanks a lot :)
– ankur43
Nov 22 at 10:13
Thanks a lot :)
– ankur43
Nov 22 at 10:13
Could you please help me to get out the name when the String is : ": 43 i Hit : GD | HRT Pav amar h Ted a3 ! ZMY1960756 : y | A : for ib Wags v, | EKO fadias =r amy; fra Electors Name : ANKIT | Rar #1 am: gob aw Father's Name: MURARI LAL | AT 1 Sex ' i I Male | 3 : 11/03/1990 S sFafafa/ oos ;"
– ankur43
Nov 22 at 10:14
Could you please help me to get out the name when the String is : ": 43 i Hit : GD | HRT Pav amar h Ted a3 ! ZMY1960756 : y | A : for ib Wags v, | EKO fadias =r amy; fra Electors Name : ANKIT | Rar #1 am: gob aw Father's Name: MURARI LAL | AT 1 Sex ' i I Male | 3 : 11/03/1990 S sFafafa/ oos ;"
– ankur43
Nov 22 at 10:14
The given String should display "ANKIT" as output
– ankur43
Nov 22 at 10:17
The given String should display "ANKIT" as output
– ankur43
Nov 22 at 10:17
Your this string looks better than earlier in your post, because here at least I see a delimiter which is
|
. You can use this regex Electors Name\s*:\s*([\w ]+)\s*\|
– Pushpesh Kumar Rajwanshi
Nov 22 at 10:20
Your this string looks better than earlier in your post, because here at least I see a delimiter which is
|
. You can use this regex Electors Name\s*:\s*([\w ]+)\s*\|
– Pushpesh Kumar Rajwanshi
Nov 22 at 10:20
1
1
Done!! Thanks!!!
– ankur43
Nov 22 at 11:22
Done!! Thanks!!!
– ankur43
Nov 22 at 11:22
|
show 10 more comments
How does the string change, and what part of the string remains the same? Do you have a code example of what you already tried?
– Stephan Hogenboom
Nov 22 at 9:01
This string is generated by getting characters from an image.So, it doesn't remain the same. The String "Electors name" is constant.
– ankur43
Nov 22 at 9:07
Then how do you know
mam-a #02.....
isn't part of the name?– Jai
Nov 22 at 9:16
beacuse i also have the document from which this string is retrieved :D
– ankur43
Nov 22 at 9:23