Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:10:49+00:00 2026-06-10T18:10:49+00:00

I have text file which has text with newline char like this. I read

  • 0

I have text file which has text with newline char like this. I read that text file into a String

random Text
State v. USA
some more text
USA v.
NY
Some more text
USA
v.LA ,  MN v. ND
USA vs. MN

I want to know offset (i.e. starting and ending char index) of patterns like [Some word starting with cap] v. [Some word starting with cap]

Or
[Some word starting with cap] vs. [Some word starting with cap]

For above example
“State v. USA” => Start=11 and End=22

“USA v.
NY” => Start=36 and End=45

I started with something like this http://rubular.com/r/T7Ii2WDADw which is not covering all cases .

So, the program could return a Map where key is Start+”,”+End and value is actual text like “State v. USA”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:10:51+00:00Added an answer on June 10, 2026 at 6:10 pm

    To cover both the cases you need to use this regex.

    \w+\s((v.)|(vs.))\s\w+
    

    In java code.

    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    
    public class Testapp {
    
    public static void main(String[] args) {
    String text = "USA v. Russia \n Some other text \n India vs. Aus";
    String regex="\\w+\\s((v.)|(vs.))\\s\\w+";
    Pattern p = Pattern.compile(regex);
    Matcher matcher = p.matcher(text);
    
    while (matcher.find()) {
        System.out.println(matcher.group()+ ":" +"start =" + matcher.start() + " end = " + matcher.end());
    }
    }
    }
    

    Output:

    Starting & ending index ofUSA v. Russia:start=0 end = 13
    Starting & ending index ofIndia vs. Aus:start=34 end = 47
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file which has a particular line something like sometext sometext
I have this xml file which has text init. i.e Hi my name is
i have a java ee project which has a text file that uses a
Supposedly I have this line in my text file which has the following format.
We have one text file which has the following text "\u5b89\u5fbd\u5b5f\u5143" When we read
I have a text file which has the following structure: 341|18 Hello world|20090225230048AAnhStI|90|$0.30|10|289|2|2|2|Is that
I have some text file which has some occurrences of the string bad in
I have a PHP file which has the following text: <div class=small_italic>This is what
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I'm having trouble with PHP text parsing I have a txt file which has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.