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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:15:17+00:00 2026-06-12T01:15:17+00:00

Here’s what I want to do: Search a document for a pattern containing RegEx,

  • 0

Here’s what I want to do:

Search a document for a pattern containing RegEx, then check if this exact pattern is present twice inside of a line.

Content of file.xml:
(some code) "testen"  (more code)  >testete<
(some code) "bleiben" (more code)  >bleiben<
(some code) "stehen"  (more code)  >stand<
(some code) "hängen"  (more code)  >hängten<
... 

Now I want to check for .*en and check if the (exact) same word occurs twice in the line. So the outcome should be:

bleiben

Because Testen != testete, stehen != stand, hängen != hängten

Is there a way to do this?

  • 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-12T01:15:18+00:00Added an answer on June 12, 2026 at 1:15 am

    You can handle this search on the first grep line by using the pattern: .*en.*en:

    grep .*en.*en your_file
    

    This will output only the lines that have en appearing twice in them.

    If you need to handle it in two back-to-back grep‘s, you could still use this same command in a piped version:

    grep .*en your_file | grep .*en.*en
    

    Also, if you ever want to increase the number of instances in the same line, you can take advantage of grep‘s -P option and use a Perl regex:

    grep -P "(.*en){2}" your_file
    

    With this, you can just change the {2} to however-many instances you want it to appear in a single line and it should work.

    EDIT (to find lines with exact same word twice)

    This is difficult without an extended pattern that can define the boundaries of a word – and your example output doesn’t really help much. To go for a straight-to-the-point example, we can just assume a “word” is any alphabetical string a-z that’s ending with en. You can customize this boundary as needed:

    grep -P "([a-z]+en).*\1" your_file
    

    This will print any line that has a word ending in en that is found elsewhere in the line (the \1).

    One caveat to mention, which relates to the word-boundary issue noted above. In the context of “bleiben” and “bleiben”, they are equal. However, in the context of “ben” and “bleiben”, this pattern will also match because it will see then ending “ben” from “bleiben” as the matching pattern (thereby using “ben” = “ben”). If this is not acceptable, you will have to establish a more-strict word-boundary (i.e. – don’t allow special characters?).

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

Sidebar

Related Questions

Here is an example: I write html code inside of textarea, then I swap
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here is the problem. I have <div id=main></div> I want to check user resolution
Here is the code in a function I'm trying to revise. This example works
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here's what I'm doing. I want to upload multipart file via Ajax to my
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here is the problem I'm trying to solve for my game. I have this

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.