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

  • Home
  • SEARCH
  • 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 4579124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:35:52+00:00 2026-05-21T20:35:52+00:00

I have the string like this: String s = word=PS1,p1,p2,p3=q1,q2|word2=PS3,p4,p5,p6=q3; or like this: String

  • 0

I have the string like this:

String s = "word=PS1,p1,p2,p3=q1,q2|word2=PS3,p4,p5,p6=q3";

or like this:

String s2 = "word3=PS2,p7,p8=q4,q5,q6|=PS3,p9=";

or like this:

String s3 = "=PS3=";

So, in formal – string contains some word definitions in dictionary, splitted by “|” symbol.

here:

  • word – word in the dictionary (optional, like in S2 or S3)

  • PS1, PS2, PS3 – Part of speech tag (required)

  • p1,p2,… – some parameters (optional)

  • q1, q2, q3, … – some another parameters (also optional)

I want to build regex, which finds all occurrences of such strings in the text and gives me the groups:

  • group1 – word
  • group2 – part of speech tag
  • group3, group4, … – parameters p
  • group(k), group(k+1), … – another parameters (q)

I don’t care for index of group of the last p parameter and first q parameter. I should know, that first group – is word (may be null), second group – part of speech, and other groups – parameters p and q.

Now I have such regex:

"([a-z]*)?=([A-Z]+)(,?[a-z]+)*=(,?[a-z]+)*")

But it doesn’t work correctly. It shows me only the last parameters p and q. I.e. (for S2) :

  • group1 = word3 – OK
  • group2 = PS2 – OK
  • group3 = p8 – NOT OK (only last p-parameter)
  • group4 = q6 – NOT OK (also last q-parameter)

Could you help me?

UPDATE:
“=”-character only the split-character between p-parameters and q-parameters. It’s not necessary in my problem. You should think, that p-parameters and q-parameters are not different.

example of real input:

String s = "bread=NOUN,plur,link=form|=VERB="
  • 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-05-21T20:35:53+00:00Added an answer on May 21, 2026 at 8:35 pm

    You can’t have a variable number of capture-groups in Regex. In .Net you could have multiple captures for each group, but not in Java. The problem for you is that the regex engine only stores the last successful match for each group. The best you could do is to match all p- and q- parameters into two big groups, and then split them up.

    Pattern pattern1 = Pattern.compile(
        "([^|=,]*)" +                // Group 1: The word. Zero or more characters.
        "=([^|=,]*)" +               // Group 2: The part of speech.
        ",?([^|=,]*(?:,[^|=,]*)*)" + // Group 3: The p-params
        "=([^|=,]*(?:,[^|=,]*)*)"    // Group 4: The q-params
    );
    Matcher matcher = pattern1.matcher("word=PS1,p1,p2,p3=q1,q2|word2=PS3,p4,p5,p6=q3");
    while (matcher.find()) {
      String word = matcher.group(1);
      String partOfSpeech = matcher.group(2);
      String pParamString = matcher.group(3);
      String qParamString = matcher.group(4);
      String[] pParams = pParamString.split(",");
      String[] qParams = qParamString.split(",");
      // Do something with the above variables...
    }
    

    I used [^|=,]* to match any non-special character.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string with some word separated by (,) like this word1, word2,word3,word5,
I have a string like this: a word {{bla|123|456}} another {{bli|789|123}} some more text
Hi I have a string like this: word1--tab--word2--tab--word3--tab--word4--tab--word5--tab--word6 I need to extract the third
i have a string like this one: $string = some text http://dvz.local/index/index/regionId/28 http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
I have a string like this in Ruby word=0 id=891efc9a-2210-4beb-a19a-5e86b2f8a49f How can I get
I have a string that looks like this: the word you need is 'hello'
I have this Word.cc that is like string class for manipulating words. I overloaded
I Have some text file. theses texts contain a string like this(a part of
I have string like this : <input name=my_name id=my_id value=my_value class=my_class /> I would
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files

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.