web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Ignore the character a...
Power Automate
Suggested Answer

Ignore the character and only include number in substring

(2) ShareShare
ReportReport
Posted on by 601
I have written below power automate to retrieve the AIS number and get count
 
substring(item()?['Subject'], indexOf(item()?['Subject'], 'AIS'), 7)
 
This retrieves the AIS number correctly. For example subject: AIS1758 Queens Walk retrieves the substring as AIS1758 which is correct
 
However some subject has below content
 
A new AIS Opportunity is created
 
As per above code, it retrieves the substring AIS Opp which is incorrect. May i know how should i modify the above code such that it retrieves only the substring which has AIS numbers and not AIS characters followed by it. 
I have the same question (0)
  • Suggested answer
    Ellis Karim Profile Picture
    12,046 Super User 2026 Season 1 on at
     
    You maybe able to use the startsWith function, if the line will always start with AIS:
     
     
    This expression checks if the string variable myText begins with the characters "AIS". If it does, it returns the first word (everything before the first space), and if it does not, it returns a null value.
     
    if(startsWith(variables('myText'),'AIS'), first(split(variables('myText'),' ')),null)
     
    Optional: If you want to check if the text contains numbers (integers), you can use a more complex expression: this strips the "AIS" prefix (e.g. from AIS1758) and checks if the remaining characters (e.g., "1758") is a valid integer:
    isInt(if(startsWith(variables('myText'),'AIS'), 
    	split(first(split(variables('myText'),' ')),'AIS')?[1],
    	null))
     
    Next, this condition checks if the output from the Compose action contains a valid value; if it is not null, it displays "Found it" alongside the value, otherwise, it outputs "Failed to find it".
     
     
     
     
    It seems that your text is coming from an email? If that is the case, you can add a filter to check if the email subject starts with AIS using a trigger condition:

     
    @startsWith(triggerBody()?['subject'], 'AIS')
     
     
    Ellis Karim
    Ellis Karim
    elliskarim.com  |  LinkedIn  |  Bluesky
    If this solved your issue, please mark it as ✅ Accepted Answer. If it helped, feel free to give it a 🩷 Like!
  • Suggested answer
    11manish Profile Picture
    1,851 on at
    Try below :
     
    In Microsoft Power Automate, you need to check that characters after “AIS” are numbers.
     
    Recommended Expression
     
    if(
      and(
        contains(item()?['Subject'], 'AIS'),
        isInt(substring(item()?['Subject'], add(indexOf(item()?['Subject'], 'AIS'), 3), 4))
      ),
      substring(item()?['Subject'], indexOf(item()?['Subject'], 'AIS'), 7),
      ''
    )
     
    Thanks
    Manish
     
  • Suggested answer
    Haque Profile Picture
    2,282 on at
     
    For experiment I just assinged the subject string in a variable.  The first screen is chekcing the string "A new AIS Opportunity is created" if it finds no digits renturns empty string.
     
    Input: "A new AIS Opportunity is created"


     
     
    Output is: empty string (''), you will see nothing in the output field. Please see the output below:



    Input : “AIS1758 Queens Walk”



     


     
    Here is my expression, again I used variable [variables('DigitAIS')] string to do experiment, replace yours with Subject string (item()?['Subject']).
    if(
      greaterOrEquals(indexOf(variables('DigitAIS'), 'AIS'), 0),
      if(
        greaterOrEquals(
          indexOf('0123456789', substring(variables('DigitAIS'), add(indexOf(variables('DigitAIS'), 'AIS'), 3), 1)),
          0
        ),
        substring(variables('DigitAIS'), indexOf(variables('DigitAIS'), 'AIS'), 7),
        ''
      ),
      ''
    )
    Yours should be:
     
    if(
      greaterOrEquals(indexOf(item()?['Subject'], 'AIS'), 0),
      if(
        greaterOrEquals(
          indexOf('0123456789', substring(item()?['Subject'], add(indexOf(item()?['Subject'], 'AIS'), 3), 1)),
          0
        ),
        substring(item()?['Subject'], indexOf(item()?['Subject'], 'AIS'), 7),
        ''
      ),
      ''
    )
    Now based on the emptiness you can ignore the next flow action or proceed.
     
     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
     
  • Suggested answer
    trice602 Profile Picture
    16,164 Super User 2026 Season 1 on at
    Here's the regex solution also.  I like to go this route because regex can handle so many different things, including subject parsing.
     
     
     
     
    Create a new sheet, with a table, can be empty.
     
    Then create a new script until the tab "Automate".
     
    Paste in script.
     
    /**
     * Returns the first AIS number found in the subject in the format AIS + digits.
     * Examples:
     *  - "AIS1758 Queens Walk" => "AIS1758"
     *  - "A new AIS Opportunity is created" => ""
     *  - "AIS01820 Something" => "AIS01820"
     */
    function main(workbook: ExcelScript.Workbook, subject: string): string {
        if (!subject) return "";
    
        // Case-insensitive match of AIS followed immediately by one or more digits
        const match = subject.match(/AIS\d+/i);
        const result = match ? match[0].toUpperCase() : "";
        return result;
    }
     
     
     
     
    And here is the config for the Run script action.
     
     
     

    ------------------------------------------------

     

     

    ⭐ If this was helpful, please like and check the box below "Does this answer your question" to help others find this too!

     

     

    Always glad to help! 💯💯💯💯💯

     

    Tom

     

    Follow me on LinkedIn - Thomas Rice, PMP | LinkedIn

  • Iantaylor2050 Profile Picture
    601 on at
    Hi @Haque
     
    Thanks. I am able to filter out the unnecessary ones.
     
    May i know how to remove the blank item from the array? I used below code but it doesn't work.
     
    @and(equals(item(), items('Apply_to_each_3')),equals(empty(item()), false))
     
  • Suggested answer
    Haque Profile Picture
    2,282 on at
     
    Could you please elboarte a bit? It would be better if you could post me how the blan items are there in the array item (in your case) so that I can write the logic?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 641

#2
Vish WR Profile Picture

Vish WR 640

#3
Haque Profile Picture

Haque 495

Last 30 days Overall leaderboard