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 9248795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:01:44+00:00 2026-06-18T10:01:44+00:00

I have got dataset like this with three columns Col1, Col2, Col2 aaa,Arizona DL

  • 0

I have got dataset like this with three columns

Col1, Col2, Col2

aaa,Arizona DL USTATES,12

bbb,Idaho DL USTATES,35

ccc,Idaho DL USTATES,28

ddd,Wisconsin DL USTATES,11

eeee,Wisconsin DL USTATES,35

What I want to do is that I want to extract the first word of the second column(what is a state name) and put it in the first column.

Expected Output:

Arizona,Arizona randam USTATES,12

Idaho,Idaho randam USTATES,35

Idaho,Idaho randam USTATES,28

Wisconsin,Wisconsin random USTATES,11

The regex that I have is

^[^,]+,([^ ]+) [^\n]+$

With my () I can extract the state name, but How do get the output? What I want is nested parenthesis, something like this

^[^,]+,(([^ ]+) [^\n]+)$

and then the output will be
\1,\2

I should point out that I want to do it using regex replace only.

Edit:

I have solved it by using regex to get all of the state names in a column and then merged it, but I want to know if there are any advanced regex which can be used here.

  • 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-18T10:01:45+00:00Added an answer on June 18, 2026 at 10:01 am

    Your regex with nested parentheses works fine; you just need to use String‘s replaceFirst method and note that Java uses $ for group references. Also note that the groups are enumerated in the order they occur in the regex, so the outer group is $1 because it starts first:

    String line = "aaa,Arizona DL USTATES,12";
    String result = line.replaceFirst("^[^,]+,(([^ ]+) [^\n]+)$", "$2, $1");
    // result is "Arizona, Arizona DL USTATES,12"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL 2008 Basically i have a dataset that looks like this: AcctID AcctType AcctSubType
I have a scenario like this in ssis - I have got two different
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have got two pages. example.com/php.com and example.com. I use this function to set
I feel like this question ought to have been covered, but I can't seem
I've got a bunch of strongly typed DataSet that each have two tables. One
I'm pretty confused on how to go about this. Say I have two columns
I have a dataset like so: | 0.1 0.2 0.3 0.4 ---------------------- 1 |
I have some VTK-files, which look like this: # vtk DataFile Version 1.0 Line
I have got a data frame (which is called data.set.y). And I would like

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.