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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:28:22+00:00 2026-06-15T06:28:22+00:00

i got a little trouble using Rexex in Powershell. It seems like there is

  • 0

i got a little trouble using Rexex in Powershell. It seems like there is a imlementation error or something.

The text i want to work with is a html file, which looks like this (Example1):

<span>[Mobile: %mobile% |] Phone: %telephone% [| Fax: %faxNumber%]</span>
<Span>

The Problem is that, caused by html editors, i also may get something like this (Example2):

<span>[Mobile: 

%mobile% |] Phone: %telephone% [| Fax: &nbsp;&nbsp;%faxNumber%]</span>

So as you see, we got linebreaks and html escaped, fixed whitespaces &nbsp;.

My Powershell Regex looks like this:

$x = $x -ireplace '(?ms)\[(.?){7}Fax(.*?)\]', 'MyReplacement1'

and this

$x = $x -ireplace '(?ms)\[(.?){7}Mobile(.*?)\]', 'MyReplacement2'

Basicly The [ marks the beginning of a variable and ] the end of it. Two problems arise from this:

  1. Since we got two variables, mobile and fax, i’m using (.?){7} to allow SOME (here exacly 7) characters and avoid matching the hole part between the first [ near Mobile and the last ] near Fax (which would happen if i would be using (.*?) instead of (.?){7}). I’m not sure if there are alternatives so that i can allow ANY number (and not 7) of chars between the starting [ and the variable keyword “Fax” for example. This would be usefull to avoid missmatches when stuff like &nbsp;&nbsp; gets added (where only 7 char would not be enough and like i said (.*?) will fail). Hope i was able to explain it (kinda hard) – if not: please feel free to ask!
  2. Powershells -replace method dosn’t offer a way to set regex options, therefore i got to use (?ms) to set DotAll and multiline modes. As you see, I’m using it within my regex pattern. However: when a newline is added, as you see in example2 between the words Mobile: and %mobile%, the regex fails and nothing gets replaced!

I’m greatfull for any help and even regex recommandations from the pros to avoid any further problems i’m not thinking about right now…

EDIT:
(Example3):

<span>[Mobile: 

%mobile% |] Phone: %telephone% [| Fax: 
%faxNumber%]</span>
  • 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-15T06:28:23+00:00Added an answer on June 15, 2026 at 6:28 am

    The trick around DotAll mode is to use [\s\S] instead of .. This character class matches any character (because it matches space and non-space characters). (As does [\w\W] or [\d\D], but the spaces seem to be kind of a convention.)

    To get around the 7 you can simply disallow closing ] before the one you actually want to match (that by the way also makes DotAll unnecessary). So something like this should work fine for you:

    \[([^\]:]*)Fax([^\]]*)\]
    

    It looks a bit ugly, but it simply means this:

    \[        # literal [
    (         # capturing group 1
      [^\]:]* # match as many non-:, non-] characters as possible
    )         # end of group 1
    Fax       # literal Fax
    (         # capturing group 2
      [^\]]*  # match as many non-] characters as possible
    )         # end of group 2
    \]        # literal ]
    

    Further reading on character classes.

    Note that none of these patterns need multiline mode m (neither yours nor mine), because all it does is make ^ and $ match line beginnings and endings, respectively. But none of the patterns contain these meta-characters. So the modifier does not do anything.

    My console output:

    PS> $x = "<span>[Mobile: %mobile% |] Phone: %telephone% [| Fax: &nbsp;&nbsp;%faxNumber%]</span>"
    PS> $x -ireplace '\[([^\]:]*)Mobile([^\]]*)\]', 'MyReplacement1'
    <span>MyReplacement1 Phone: %telephone% [| Fax: &nbsp;&nbsp;%faxNumber%]</span>
    PS> $x -ireplace '\[([^\]:]*)Fax([^\]]*)\]', 'MyReplacement2'
    <span>[Mobile: %mobile% |] Phone: %telephone% MyReplacement2</span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a little problem, it seems simple (personally I think it is), but
I have a little trouble getting gettext to work. I made a simple test
(This topic is not about .setfillafter(true)). I got a little trouble with the animations
I'm having a little trouble with a jQuery plugin wrote. I've got it working
i have a little trouble while making my first play application. I got a
I've got some trouble with the <video> element I guess. I have a little
I'm just getting started with jQuery, having a little trouble. Got a table of
I've just got myself into a little mess and am having trouble thinking myself
I got a little ruby app going and I'm having trouble with one part.
I'm having a little trouble setting a form using inner HTML: document.getElementById(Button).innerHTML='<form action=add.php method=post

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.