regex - Detect a specific pattern inside a url /us-en/ to something else
问题描述
I'm looking for a way to replace a part in a url with another part.
Here is the url:
http://localhost:8888/sa-ar/product-list.html?category=154
I want to replace this part /sa-ar/ with /web/
knowing that /sa-ar/ may change dynamically to any other country and language something like /us-en/ etc.
what is the correct regex to be able to detect the pattern /sa-ar/
This is what I have achieved so far \/(\S{2}-\S{2})\/
Which works except when applied to .htaccess it wouldn't
解决方案
RewriteRule ^[a-z]{2}-[a-z]{2}/(.+) /web/$1 [R=301,L]
推荐阅读
- typescript - 打字稿假设我返回任何字符串,即使显式检查返回值是否包含在特定字符串的数组中
- r - 在分组后删除异常值,然后计算每组的平均值
- javascript - 函数不会让它过去 else if
- amazon-web-services - 在 Chrome 上向 S3 发送 100MB+ 文件时内存崩溃
- android - 使用 RxBLe Android 订阅通知更改
- android - 当 CoroutineScope 被取消时,Coroutine StateFlow 停止发射
- javascript - 从选择列表选项更改 CSS 颜色
- java - 在我的 GUI 类中找不到主要方法
- reactjs - 使用 jest 和酵素模拟 material-ui/pickers 的 onChange
- excel - 使用 NetworkDays_Intl 的运行时错误 1004