从字符串返回以特定后缀结尾的单词(Returning word from string which ends in specific suffix)
我需要在SQL Server(2014)中以特定后缀结尾的列中返回一个单词
在这种情况下“简历”
示例:垫圈T1 11CV金EA
来自子串的期望结果:11CV我知道我将不得不使用像Substrings和Charindexes这样的东西。
这是我到目前为止:
SUBSTRING(PartDescription, 1 ,CHARINDEX('CV', PartDescription)+1) AS [CV]
但它只返回字符串直到我想要的后缀。
示例:“Washer T1 11CV”理想情况下,我只想返回有问题的单词。
任何帮助将非常感激
I need to return a word in a column which ends in a specific suffix in SQL Server (2014)
In this case "CV"
Example: Washer T1 11CV Gold EA
Desired outcome from substring: 11CVI know I will have to use something like this involving Substrings and Charindexes.
This is what I have so far:
SUBSTRING(PartDescription, 1 ,CHARINDEX('CV', PartDescription)+1) AS [CV]
But it only returns the string up until the suffix I want.
Example: "Washer T1 11CV"Ideally I just want to return the word in question.
Any help would be much appreciated
原文:https://stackoverflow.com/questions/43218862
最满意答案
这是你想要的正则表达式:
\$(\d+\.\d+)
要测试的红宝石代码:
str1 = 'Your Product Costs $10.00' str2 = 'Your Product Costs $100.00' regexp = /\$(\d+\.\d+)/ regexp.match str1 # => <MatchData "$10.00" 1:"10.00"> regexp.match str2 # => <MatchData "$100.00" 1:"100.00">
关键是检查
.
。 有一个很棒的网站来测试你的正则表达式: http : //rubular.com/Here's the regexp you want:
\$(\d+\.\d+)
The ruby code to test:
str1 = 'Your Product Costs $10.00' str2 = 'Your Product Costs $100.00' regexp = /\$(\d+\.\d+)/ regexp.match str1 # => <MatchData "$10.00" 1:"10.00"> regexp.match str2 # => <MatchData "$100.00" 1:"100.00">
The key is to check for the
.
. There's a great website for testing your regular expressions: http://rubular.com/
相关问答
更多-
这是你想要的正则表达式: \$(\d+\.\d+) 要测试的红宝石代码: str1 = 'Your Product Costs $10.00' str2 = 'Your Product Costs $100.00' regexp = /\$(\d+\.\d+)/ regexp.match str1 # =>
regexp.match str2 # => 关键是检查. ... -
您可以完全从您的正则表达式中删除.* 。 它所做的只是匹配整个字符串,然后回溯,直到找到搜索字符串。 删除它,看看它是否仍然很慢。 You can drop the .* from your regex completely. All it does is match the entire string and then backtrack until your search string is found. Remove it and see if it's still as slow.
-
你的模式会导致灾难性的回溯 。 灾难性的部分可以归纳为: (.+)* +和*在一些引擎中以灾难性的方式进行交互。 目前还不清楚你想要匹配什么,但它可能是这样的: ^[\w\-]+( [\w\-]+)*$ 这匹配( 如在rubular.com上看到的 ): hello world 99 bottles of beer on the wall this_works_too 并拒绝: not like this, not like this hey what the @! too many spa ...
-
Ruby 正则表达式是PCRE正则表达式,因为PCRE代表Perl兼容正则表达式,并为它支持的正则表达式定义特定语法。 有关单个PCRE正则表达式功能的帮助,请参阅我链接到的第二篇文章,对于ruby特定方法,请参阅第一篇(正如您将看到的,实际使用的正则表达式的语法是相同的) 编辑:正如评论中所指出的,ruby使用的正则表达式引擎是Onigmo ,根据链接到页面,它具有Perl 5.10的一些新功能。 PCRE是一个正则表达式库,“PCRE的当前实现大致与Perl 5.12相对应”,因此边缘可能存在一些差异。 ...
-
如果params["user][:role_ids]为nil 或其他假值,它会将[]分配给params["user][:role_ids] ... 否则,它保留params["user][:role_ids]的原始值 例 variable = nil variable ||= "string" puts variable # "string" variable2 = "value" variable2 ||= "string" puts variable2 # "value" It assign ...
-
此页面可能对您有用。 http://rvm.io/integration/passenger/ This page might useful for you. http://rvm.io/integration/passenger/
-
与JavaScript相比,正则表达式在Ruby中表现不佳(Regular Expression performing poorly in Ruby compared to JavaScript)[2023-08-07]
不知道为什么1.8.7中的正则表达式解析器比来自JS.2或Oniguruma的1.9.2中的正则解析器慢得多,但可能这个特殊的正则表达式可以从包含@符号和原子组的前缀中受益: EMAIL_REGEXP = / ^ (?>(( # atomic group start ([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+ (\.([a-z]|\d|[!#\$%&'\*\+\ ... -
结果问题与sudo和Ubuntu有关。 RVM依赖于rvm_path环境变量来开始。 根据另一个问题的答案, sudo不保留某些安全Linux版本中的PATH变量。 我不知道它是否应该保留rvm_path变量,但无论如何,它不在我的Ubuntu版本上。 因此, sudo gem install的结果是在sudo gem install过程中默认的RVM提供的Ruby版本不可用,并且使用了system-default。 在我的情况下是版本1.8。 安装似乎成功,但它没有正确的宝石版本。 解决方案只是使用gem ...
-
所有RVM命令(例如rvm install和rvm use )都可以采用rvm install ruby-1.9.2-p290 ,例如: rvm install ruby-1.9.2-p290 。 如果你没有指定,将使用最新的可用补丁级别。 All the RVM commands, such as rvm install and rvm use, can take a patchlevel, e.g.: rvm install ruby-1.9.2-p290. If you don't specify o ...
-
Ruby 1.9.2中机架级别的SystemStackError,而不是1.8.7(SystemStackError at the rack level in Ruby 1.9.2, not 1.8.7)[2023-07-11]
这看起来像Bug 3144 ,说直接引用助手。 Rails.application.routes.url_helpers This looks like Bug 3144, saying to reference the helper directly. Rails.application.routes.url_helpers