regexpi - Match regular expression (case insensitive) (2024)

Match regular expression (case insensitive)

collapse all in page

Syntax

startIndex = regexpi(str,expression)

[startIndex,endIndex]= regexpi(str,expression)

out = regexpi(str,expression,outkey)

[out1,...,outN]= regexpi(str,expression,outkey1,...,outkeyN)

___ = regexpi(___,option1,...,optionM)

___ = regexpi(___,'forceCellOutput')

Description

startIndex = regexpi(str,expression) returnsthe starting index of each substring of str thatmatches the character patterns specified by the regular expression,without regard to letter case. If there are no matches, startIndex isan empty array.

example

[startIndex,endIndex]= regexpi(str,expression) returnsthe starting and ending indices of all matches.

out = regexpi(str,expression,outkey) returnsthe output specified by outkey. For example,if outkey is 'match', then regexpi returnsthe substrings that match the expression rather than their startingindices.

[out1,...,outN]= regexpi(str,expression,outkey1,...,outkeyN) returnsthe outputs specified by multiple output keywords, in the specifiedorder. For example, if you specify 'match','tokens',then regexpi returns substrings that match theentire expression and tokens thatmatch parts of the expression.

___ = regexpi(___,option1,...,optionM) modifiesthe search using the specified option flags. For example, specify 'matchcase' toperform a case-sensitive match. You can include any of the inputsand request any of the outputs from previous syntaxes.

example

___ = regexpi(___,'forceCellOutput') returnseach output argument as a scalar cell. The cells contain the numericarrays or substrings that are described as the outputs of the previoussyntaxes. You can include any of the inputs and request any of theoutputs from previous syntaxes.

Examples

collapse all

Pattern Matching

Open Live Script

Find words that start with c, end with t, and contain one or more vowels between them.

str = 'bat cat can car COAT court cut ct CAT-scan';expression = 'c[aeiou]+t';startIndex = regexpi(str,expression)
startIndex = 1×4 5 17 28 35

Values in startIndex indicate the index of the first character of each word that matches the regular expression.

The regular expression 'c[aeiou]+t' specifies this pattern:

  • c must be the first character.

  • c must be followed by one of the characters inside the brackets, [aeiou].

  • The bracketed pattern must occur one or more times, as indicated by the + operator.

  • t must be the last character, with no characters between the bracketed pattern and the t.

Case-Sensitive Match

Open Live Script

Match letter case in all or part of an expression.

By default, regexpi performs case-insensitive matching.

str = 'A character vector with UPPERCASE and lowercase text.';expression = '\w*case';matchStr = regexpi(str,expression,'match')
matchStr = 1x2 cell {'UPPERCASE'} {'lowercase'}

Use the regexp function with the same syntax as regexpi to perform case-sensitive matching.

matchWithRegexp = regexp(str,expression,'match')
matchWithRegexp = 1x1 cell array {'lowercase'}

To disable case-sensitive matching for regexp, use the 'ignorecase' option.

matchWithIgnorecase = regexp(str,expression,'match','ignorecase')
matchWithIgnorecase = 1x2 cell {'UPPERCASE'} {'lowercase'}

For multiple expressions, enable and disable case-insensitive matching for selected expressions using the (?i) and (?-i) search flags.

expression = {'(?-i)\w*case';... '(?i)\w*case'};matchStr = regexp(str,expression,'match');celldisp(matchStr)
 matchStr{1}{1} = lowercase matchStr{2}{1} = UPPERCASE matchStr{2}{2} = lowercase 

Input Arguments

collapse all

optionSearch option
'once' | 'warnings' | 'matchcase' | 'emptymatch' | 'dotexceptnewline' | 'lineanchors' | ...

Search option, specified as a character vector. Options come in pairs: one option that corresponds to the default behavior, and one option that allows you to override the default. Specify only one option from a pair. Options can appear in any order.

Default

Override

Description

'all'

'once'

Match the expression as many times as possible (default), or only once.

'nowarnings'

'warnings'

Suppress warnings (default), or display them.

'ignorecase'

'matchcase'

Ignore letter case (default), or match case.

'noemptymatch'

'emptymatch'

Ignore zero length matches (default), or include them.

'dotall'

'dotexceptnewline'

Match dot with any character (default), or all except newline (\n).

'stringanchors'

'lineanchors'

Apply ^ and $ metacharacters to the beginning and end of a character vector (default), or to the beginning and end of a line. The newline character (\n) specifies the end of a line. The beginning of a line is specified as the first character, or any character that immediately follows a newline character.

'literalspacing'

'freespacing'

Include space characters and comments when matching (default), or ignore them. With freespacing, use '\ ' and '\#' to match space and # characters.

Data Types: char

Output Arguments

collapse all

More About

collapse all

Tokens

Tokens are portions of the matched text thatcorrespond to portions of the regular expression. To create tokens,enclose part of the regular expression in parentheses.

For example, this expression finds a date of the form dd-mmm-yyyy,including tokens for the day, month, and year.

str = 'Here is a date: 01-Apr-2020';expression = '(\d+)-(\w+)-(\d+)';mydate = regexp(str,expression,'tokens');mydate{:}
ans = 1×3 cell array {'01'} {'Apr'} {'2020'}

You can associate names with tokens so that they are more easilyidentifiable:

str = 'Here is a date: 01-Apr-2020';expression = '(?<day>\d+)-(?<month>\w+)-(?<year>\d+)';mydate = regexp(str,expression,'names')
mydate = struct with fields: day: '01' month: 'Apr' year: '2020'

For more information, see Tokens in Regular Expressions.

Extended Capabilities

Version History

Introduced before R2006a

See Also

regexp | regexprep | regexptranslate | strfind | strjoin | strsplit | strrep | contains | replace

Topics

  • Lookahead Assertions in Regular Expressions
  • Dynamic Regular Expressions

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

regexpi - Match regular expression (case insensitive) (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

regexpi - Match regular expression (case insensitive) (2024)
Top Articles
HOW RUNNING SHAPES YOUR BODY, BOOSTS FITNESS, AND UPLIFTS THE MIND
Credit Union CFO Job Description - Financial Executive Recruiters
Td Youth Account
The Miami Herald from Miami, Florida
417-990-0201
Varsity Tutors, a Nerdy Company hiring Hoboken Vietnamese Tutor in Hoboken, NJ | LinkedIn
Stanley Steemer Medford Oregon
No Hard Feelings Showtimes Near Amc Classic Pekin 14
25X11X10 Atv Tires Tractor Supply
Glamour Dresser Ffxiv Housing
Dutch Sheets Give Him 15 Today's Message Today
Call2Recycle Sites At The Home Depot
Nexus 5Gang praktische Erfahrungen
Page 4444 – Christianity Today
❤️ Red Heart Emoji Guide For All Girls and Boys
Craigslist Rutland Vt Apartments
Thankathon
Best Restaurants Ventnor
Nioh 2 Elemental Damage
Baby Alien Fan Bus Video: A Closer Look
2005 Chevy Colorado 3.5 Head Bolt Torque Specs
Does Sheetz Drug Test For Weed
Orlando Rub Rating
Bad Moms 123Movies
Visiting Truist Park: This Is What You Need to Know
Porsche Girl Photos Head
Translations Of Linear Functions Worksheet Answer Key
Wo die Säbelzahntiger brüllen – die Serie „La Brea“ startet bei Sky
Classy Spa Fort Walton Beach
Craigslist Pets Sac
Dit zijn de 14 beste restaurants van Amsterdam
Blak Stellenanzeigen
Bad And Busted Georgia
Galluch's Menu
Papa Johns Mear Me
Shaanxi Y-9 Medium-Lift Transport Aircraft
Ame Bibabi Net Worth
Marianas Market Weekly Ad
Montgomery Advertiser Obituaries
Alineaciones De Rcd Espanyol Contra Celta De Vigo
Kathy Vold From Heartland
European Wax Center Toms River Reviews
Alcon National Driving Center Inc
Eric Rohan Justin Obituary
Games Like Mythic Manor
Strip Clubs In Bowling Green
Watch The Lovely Bones Online Free 123Movies
Aveda Caramel Toner Formula
Jess Bush Wikifeet
Covington Va Craigslist
ROG Falchion Ace HFX | Gaming keyboards|ROG - Republic of Gamers|ROG USA
Round Cake Pans Walmart
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6584

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.