# Regex issue

**URL:** <https://www.ruby-forum.com/t/regex-issue/215908>\
**Category:** NGINX\
**Created:** [January 19, 2012, 8:08am UTC](https://www.ruby-forum.com/t/regex-issue/215908 "2012-01-19T08:08:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 19, 2012, 8:08am UTC](https://www.ruby-forum.com/t/regex-issue/215908/1 "2012-01-19T08:08:01Z")

</div>

For some reason, I am unable to take a URI like  
[example.com/manufacturers/metlox/0?page=13](http://example.com/manufacturers/metlox/0?page=13) and change it to  
[example.com/manufacturers/m](http://example.com/manufacturers/m)

It seems like the curly braces aren’t working. I’ve tried the following  
without results:

location ~\* /manufacturers/ {

```
    rewrite "^/manufacturers/(.{1})/(.*)$" 

```

/manufacturer/directory/$1  
redirect;

```
    }

```

location ~\* /manufacturers/ {

```
    rewrite "^/manufacturers/([a-z] {1})/(.*)$"

```

/manufacturer/directory/$1 redirect;

```
    }

```

location ~\* /manufacturers/ {

```
    rewrite "^/manufacturers/([a-z]?)/(.*)$" 

```

/manufacturer/directory/$1  
redirect;

```
    }

```

I am new to regex, so maybe this is something simple. What I want to get  
is  
the first letter of first captured word. What I can do is pull the  
entire  
word with (.\*), but not the first letter only.

Any help would be appreciated.

Thanks in advance.

Using nginx 0.8.53 reverse proxy in front of apache

---

<div class="post-metadata">

**Author:** ![mpratt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecccb3/32.png) [@mpratt](https://www.ruby-forum.com/u/mpratt)\
**Post date:** [January 19, 2012, 8:17am UTC](https://www.ruby-forum.com/t/regex-issue/215908/2 "2012-01-19T08:17:54Z")

</div>

On Wed, Jan 18, 2012 at 11:58 PM, mpratt [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> For some reason, I am unable to take a URI like  
> [example.com/manufacturers/metlox/0?page=13](http://example.com/manufacturers/metlox/0?page=13) and change it to  
> [example.com/manufacturers/m](http://example.com/manufacturers/m)
> 
> It seems like the curly braces aren’t working. I’ve tried the following  
> without results:

/(.{1})/  
This will match and capture one character between slashes  
Examples:  
/a/ → $1: a  
/asd/ → no match (three characters)

/([a-z]\*)/  
This one will match and capture one or less letter between slashes  
Examples:  
/a/ → $1: a  
/asd/ → no match

/([a-z]?)/  
This one is equivalent to /([a-z]\*)/

/([a-z] ?)/  
This one will match and capture one letter followed by space between  
slashes  
Examples:  
/a/ → no match  
/a / → $1: " a"  
/asd/ → no match

/(.).\*/  
This one will match one or more characters between slashes and capture  
the first character  
/a/ → $1: a  
/a / → $1: a  
/asd/ → $1: a

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![mpratt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecccb3/32.png) [@mpratt](https://www.ruby-forum.com/u/mpratt)\
**Post date:** [January 19, 2012, 8:19am UTC](https://www.ruby-forum.com/t/regex-issue/215908/3 "2012-01-19T08:19:45Z")

</div>

Sorry, I made mistake

> /([a-z] ?)/  
> This one will match and capture one letter optionally followed by space between  
> slashes  
> Examples:  
> /a/ → $1: a  
> /a / → $1: "a "  
> /asd/ → no match

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![mpratt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecccb3/32.png) [@mpratt](https://www.ruby-forum.com/u/mpratt)\
**Post date:** [January 19, 2012, 2:36pm UTC](https://www.ruby-forum.com/t/regex-issue/215908/4 "2012-01-19T14:36:19Z")

</div>

Thank you so much. This explanation really helps.

Sorry for the nearly duplicate post. This one came through the mailing  
list delayed before I discovered this forum.

Thanks again!

Posted at Nginx Forum:

> **[Re: regex issue](https://forum.nginx.org/read.php?2,221431,221450#msg-221450)**
>
> For some reason, I am unable to take a URI like example.com/manufacturers/metlox/0?page=13 and change it to example.com/manufacturers/m It seems like the curly braces aren't working. I've tried the following without results: location ~\* /man
