1. [Home](<https://delaparra-services.nl/>) 
1. [Knowledge hub](<https://delaparra-services.nl/knowledge-hub>) 
1. [/y (Sticky)](<https://delaparra-services.nl/knowledge-hub/y-sticky>)

  

Category: Regex flags 

# /y (Sticky)

  Explained by [Reinier de la Parra](<https://delaparra-services.nl/about>)  Updated November 25, 2026    

## What is /y (Sticky)?

 

/y (Sticky): Matches only at the lastIndex position of the regex; does not scan forward. The ` y ` flag in JavaScript makes a regex sticky. It only tries to match at the exact position stored in ` lastIndex `, and fails if the text there does not fit. It never searches further along the string.

 

Definition source [Coders Lingo](<https://coderslingo.com/resources/open-dataset/>), [CC BY 4.0](<https://creativecommons.org/licenses/by/4.0/>)

 

## Frequently asked questions about /y (Sticky)

  

### How is /y (Sticky) used in practice?

 

This is what you need for a tokenizer or a simple parser. You read one token, move ` lastIndex ` to the end of it, and try the next pattern at exactly that spot. Without ` y `, the engine might skip unknown characters and find a match later, which hides syntax errors in the input.

    

### What should you keep in mind with /y (Sticky)?

 

It is similar to PHP's ` A ` modifier. Because the regex object carries state in ` lastIndex `, create it inside the function that uses it, or reset ` lastIndex ` before each run. Sharing a sticky regex between calls is a reliable way to get bugs that only appear sometimes.

 

## At a glance

   CategoryRegex flags Explained by[Reinier de la Parra](<https://delaparra-services.nl/about>) UpdatedNovember 25, 2026

 

## More Regex flags terms

 

- [/r (Right-to-Left)](<https://delaparra-services.nl/knowledge-hub/r-right-to-left>) 
- [/s (DotAll (single line))](<https://delaparra-services.nl/knowledge-hub/s-dotall-single-line>) 
- [/U (Ungreedy)](<https://delaparra-services.nl/knowledge-hub/u-ungreedy>) 
- [/u (Unicode)](<https://delaparra-services.nl/knowledge-hub/u-unicode>) 
- [/v (Unicode Sets)](<https://delaparra-services.nl/knowledge-hub/v-unicode-sets>) 
- [/x (Extended / Verbose)](<https://delaparra-services.nl/knowledge-hub/x-extended-verbose>)

 

[All terms starting with a number or symbol](<https://delaparra-services.nl/knowledge-hub#letter-other>)

 

## Skills

 

- ### Regex flags across languages

 

Use when writing, porting or debugging a regular expression and its flags/modifiers across languages and tools - JavaScript (g i m s u v y d), PCRE/PHP (i m s x u A D U J), Python re (re.I, re.M, re.S, re.X, re.A), .NET (RegexOptions), POSIX grep/sed. Also use for Laravel \`regex:\` validation rules and for catastrophic backtracking risks.

 [View skill](<https://delaparra-services.nl/skills/regex-flags-cross-language>) [Download zip](<https://delaparra-services.nl/skills/regex-flags-cross-language/download>) 
- ### Regex builder

 

Use when the user asks to create, debug, explain, validate, or optimize a regular expression or replacement for a specific engine. Verifies representative matches, non-matches, captures, escaping, portability limits, and backtracking risk in the target runtime.

 [View skill](<https://delaparra-services.nl/skills/regex-builder>) [Download zip](<https://delaparra-services.nl/skills/regex-builder/download>)

 [Download all skills (zip)](<https://delaparra-services.nl/knowledge-hub/y-sticky/skills.zip>)

 

## Manuals

 

- [Regex for beginners](<https://delaparra-services.nl/manuals/regex-voor-beginners>) 
- [Installing Visual Studio Code](<https://delaparra-services.nl/manuals/visual-studio-code-installeren>)

 

## Related services

 

- [Custom software and web applications](<https://delaparra-services.nl/services#service-03>)

Perhaps your customers need somewhere to download their invoices, or your staff are managing bookings in a spreadsheet.

 

## Need any help?

 

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.

  [Get in touch](<https://delaparra-services.nl/availability>)

[HTML version](https://delaparra-services.nl/knowledge-hub/y-sticky)
