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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:50:01+00:00 2026-05-26T13:50:01+00:00

I am trying to write a regex using perl but I need some help.

  • 0

I am trying to write a regex using perl but I need some help.
What I want to do is the following, suppose that I have these texts as examples:

1- [NP some/NN text/NNP here/NNP]

I am interested in the words labelled by /NNP, so I want my regex to search every line until it finds:
[NP then a space then (may or may not find) a word labeled with /NN then one or more words labelled with /NNP (and would contain some special characters).

I want to extract the words labelled with /NNP from each line so the result would be:

1- text here

what I have done so far is to extract the labelled words with /NNP from all the examples

while ($line =~ m/\s(\S*?)\/NNP/gs)
{
        my $word = $1;
        print $word." ";
} 
print "\n";

Any Ideas pleas?

  • 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-26T13:50:01+00:00Added an answer on May 26, 2026 at 1:50 pm

    Perhaps:

        #!/usr/bin/env perl
        use strict;
        use warnings;
        while (<DATA>) {
            while ( m{(\[NP.+?\])}g ) {
            my $piece = $1;
            1 while $piece =~ m{(\w+)/NNP}g and printf "%s ",$1;
            print "\n";
            }
        }
        __DATA__
        1- [NP Almst$Ar/NN Ebd/NNP AlmEz/NNP AbrAhym/NNP] [NP Almhnds/NN hAnY/NNP HjAb/NNP]
        2- [NP xAld/NNP ftH/NNP Allh/NNP] [NP ESAm/NNP $rf/NNP] [NP AlqAhrp/NNP]
    

    And then you asked to be able to skip lines with only one labeled word. For that, I might do:

    #!/usr/bin/env perl
    use strict;
    use warnings;
    my @line = ();
    while (<DATA>) {
        while ( m{(\[NP.+?\])}g ) {
            my $piece = $1;
            while ( $piece =~ m{(\w+)/NNP}g ) {
                push @line, $1;
            }
            print "@line\n", @line = () if @line && @line > 1;
        }
    }
    __DATA__
    1- [NP Almst$Ar/NN Ebd/NNP AlmEz/NNP AbrAhym/NNP] [NP Almhnds/NN hAnY/NNP HjAb/NNP]
    2- [NP xAld/NNP ftH/NNP Allh/NNP] [NP ESAm/NNP $rf/NNP] [NP AlqAhrp/NNP]
    3- [Nothing of interest here]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to write a regex that will remove whitespace following a
I'm trying to write a regex that will match everything BUT an apostrophe that
I'm trying to write something that format Brazilian phone numbers, but I want it
I'm trying to write some replacement regex that will insert a locale code into
I have a string that looks like: Pretext<thecontentineed> I' trying to write a regex
I need help from the Regex wizards out there. I am trying to write
Need a little help with a regex I'm trying to match a string that
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a regex that will parse out the directory and filename
I'm trying to write a regular expression that validates a date. The regex needs

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.