小编Dav*_*ave的帖子

如何检查字符串是否包含来自另一个字符串的至少一个字符?

我正在使用Java 6.我有一个包含"特殊"字符的字符串 - "!@#$%^&*()_".如何编写Java表达式来检查另一个字符串"password"是否至少包含第一个字符串中定义的一个字符?我有

regForm.getPassword().matches(".*[\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+].*")
Run Code Online (Sandbox Code Playgroud)

但我不想对特殊字符进行硬编码,而是将它们从属性文件加载到字符串中.因此,在从文件加载后,我无法确定如何正确地逃避所有内容.

java regex

0
推荐指数
1
解决办法
2万
查看次数

运行我的Gradle Liquibase插件时,我在哪里放置MySql JAR依赖项?

我在Windows 7上使用Gradle 2.7.我想在运行时运行我的Liquibase插件

gradle build
Run Code Online (Sandbox Code Playgroud)

所以我在build.gradle文件中有以下代码

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile (

        'commons-beanutils:commons-beanutils:1.8.3',
        'commons-collections:commons-collections:3.2.1',
        'org.apache.commons:commons-dbcp2:2.1.1',
        'commons-lang:commons-lang:2.6',
        'commons-logging:commons-logging:1.2',
        'org.apache.commons:commons-pool2:2.4.2',
        'org.directwebremoting:dwr:3.0.0-RELEASE',
        'org.apache.httpcomponents:httpclient:4.5.1',
        'org.codehaus.jackson:jackson-core-asl:1.9.13',
        'org.codehaus.jackson:jackson-mapper-asl:1.9.13',
        'net.sf.json-lib:json-lib:2.4:jdk15',
        'jstl:jstl:1.2',
        'log4j:log4j:1.2.15',
        'joda-time:joda-time:2.8.2',
        'org.mybatis:mybatis:3.3.0',
        'org.mybatis:mybatis-spring:1.2.3',
        'mysql:mysql-connector-java:5.1.36',
        'org.springframework:spring-aop:4.2.1.RELEASE',
        'org.springframework:spring-aspects:4.2.1.RELEASE',
        'org.springframework:spring-beans:4.2.1.RELEASE',
        'org.springframework:spring-context:4.2.1.RELEASE',
        'org.springframework:spring-context-support:4.2.1.RELEASE',
        'org.springframework:spring-core:4.2.1.RELEASE',
        'org.springframework:spring-expression:4.2.1.RELEASE',
        'org.springframework:spring-instrument:4.2.1.RELEASE',
        'org.springframework:spring-instrument-tomcat:4.2.1.RELEASE',
        'org.springframework:spring-jdbc:4.2.1.RELEASE',
        'org.springframework:spring-jms:4.2.1.RELEASE',
        'org.springframework:spring-messaging:4.2.1.RELEASE',
        'org.springframework:spring-test:4.2.1.RELEASE',
        'org.springframework:spring-tx:4.2.1.RELEASE',
        'org.springframework:spring-web:4.2.1.RELEASE',
        'org.springframework:spring-webmvc:4.2.1.RELEASE'
    )

...
liquibase {
  activities {
    main {
        File propsFile = …
Run Code Online (Sandbox Code Playgroud)

mysql dependencies liquibase gradle

0
推荐指数
1
解决办法
2118
查看次数

在Java 6中比较布尔对象的简短方法是什么?

我正在使用Java 6.我有两个布尔对象,a和b.我如何比较两者的价值?我想出了这个,但看起来真的很漫长而且凌乱......

(a == null && b == null) || (a != null && b != null && a.booleanValue().equals(b.booleanValue()))
Run Code Online (Sandbox Code Playgroud)

我喜欢Apache的StringUtils.equals(a,b)方法来比较字符串,但似乎没有一个与BooleanUtils等效的方法.

java boolean compare

0
推荐指数
1
解决办法
97
查看次数

为什么我的正则表达式没有告诉我字符串是否包含数字?

我正在使用Ruby 2.4.如何检查字符串是否包含任何数字?我正在尝试这个

2.4.0 :002 > line = "abcdef"
 => "abcdef"

2.4.0 :007 > line =~ /^^[0-9]+$/
 => nil 
Run Code Online (Sandbox Code Playgroud)

我认为"^"是"非"字符,但我不确定它是如何工作的,因为我知道它也是短语起始字符.无论如何,感谢帮助, -

ruby regex string numbers

0
推荐指数
1
解决办法
64
查看次数

如何从 Rails 中的相对 URL 构建绝对 URL?

我正在使用 Rails 5。我正在尝试找出一种方法,根据我从锚标记的 href 属性中删除的值来获取绝对 URL。我想出了

url = a.attr("href")
if url !~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
  url = "http://#{url}"
end
Run Code Online (Sandbox Code Playgroud)

认为如果 href 只是“www.mydomain.com”,我可以通过附加“http://”来创建正确的 URL。然而,如果URl是相对的(例如“/abc/def”),则上述逻辑失败。有没有一种万无一失的方法可以从锚标记的 HREF 属性构建绝对 URL,该属性本身可能是也可能不是绝对 URL?请注意,我确实可以访问包含带有锚标记的页面的原始 URL。

编辑: 但是你是说,嘿,对不起,SOB,这不是浏览器处理 href 的方式。如果它看到“www.whatever.com”,它会将其视为相对路径!所以你的问题是假的!好吧,纸杯蛋糕,尽管你是对的,但这不是我的问题。我想识别一个域并将其转换为有效的 URL,并识别以“/”开头的路径并将其转换为有效的 URL。你说不可能?以此作为你的答案,当其他人同意你的观点时,你的分数就会上升。

ruby url ruby-on-rails href ruby-on-rails-5

0
推荐指数
1
解决办法
2770
查看次数

为什么Ruby告诉我在场?有价值的时候是假的吗?

我想

arg.present?
Run Code Online (Sandbox Code Playgroud)

是为了检查一个字符串是空的还是零的真相和光,但是我注意到一个令人困惑的情况.如果我的字符串是:

arg = "\t"
Run Code Online (Sandbox Code Playgroud)

我得到了错误的结果:

2.4.0 :003 > arg = "\t"
 => "\t"
2.4.0 :004 > arg.present?
 => false
Run Code Online (Sandbox Code Playgroud)

检查我的字符串参数是空还是零的更简单的方法是什么?当然,我可以写,arg.empty? || arg.nil?但我正在寻找一种更简洁的方式.

ruby string ruby-on-rails activesupport is-empty

0
推荐指数
1
解决办法
158
查看次数

在 Rails 中,如何删除数组中的所有对象?

我正在使用 Rails 5,我想删除一组对象。在之前的帖子中,我读到“destroy_all”是真理和光明。我有两个对象数组,我将它们减去以获得第三个数组

  unused_currencies = all_currencies - currencies_from_feed
  unused_currencies.destroy_all
Run Code Online (Sandbox Code Playgroud)

但是在使用时出现destroy_all了这个错误:

NoMethodError: undefined method `destroy_all' for #<Array:0x007feea8878770>
Run Code Online (Sandbox Code Playgroud)

ruby arrays ruby-on-rails destroy ruby-on-rails-5

0
推荐指数
1
解决办法
4960
查看次数

如何防止在文本框中输入前导空格?

我正在使用 jQuery 2。如果文本框中的空格是前导空格(例如在字符串的开头),我如何防止在文本框中输入空格?我以为这会做到

   $(document).on("keyup","#s" ,function(evt){
     var firstChar = $("#s").val()
     if(evt.keyCode == 32 && firstChar){
       $("#s").val( $("#s").val().trim() )
       console.log(" called ")
       return false;
     }
  })
Run Code Online (Sandbox Code Playgroud)

基本上它确实如此,但它有点马虎。你可以看到这个空间被输入然后被移除,我正在寻找稍微平滑的东西——这个空间甚至没有首先出现在教科书中。

javascript jquery whitespace keydown onkeyup

0
推荐指数
1
解决办法
4041
查看次数

何时使用 AWS Lambda,何时使用 Kubernetes (EKS)?

我们正在尝试评估扩展 J2EE Web 应用程序和使用 AWS 托管服务的最佳方法。我们是否有理由在 Kubernetes (EKS) 上使用 Lambda 服务?虽然 Lambda 似乎可以扩展功能单元,但我不清楚为什么有人会用它来代替 Kubernetes,因为 Kubernetes 可以根据性能指标复制容器。

amazon-web-services kubernetes aws-lambda amazon-eks jakarta-ee

0
推荐指数
1
解决办法
2784
查看次数

如何获取字典键组合的唯一值集?

我正在使用 Python 3.7。我有一个字典列表,例如

my_dict = [{"a": 1, "b": 5, "c": 6}, {"a": 1, "b": 5, "c": 2}, {"a": 2, "b": 1, "c": 6}]
Run Code Online (Sandbox Code Playgroud)

如果我想获得单个键的唯一值集,例如“a”,我可以

set(d['a'] for d in my_dict)
Run Code Online (Sandbox Code Playgroud)

但是我如何获得键组合的唯一值集,比如“a”和“b”?在上面的例子中,答案是

[[1, 2], [1, 5]]
Run Code Online (Sandbox Code Playgroud)

python dictionary unique python-3.x python-3.7

0
推荐指数
1
解决办法
116
查看次数

在 Angular 14 中,如何在独立组件中包含子组件?

我正在使用 Angular 14。我有一个独立组件,我想在其中包含另一个模块的子组件。独立组件看起来像

<div>
    <child-component></child-component>
</div>
Run Code Online (Sandbox Code Playgroud)

它的服务文件是

@Component({
  selector: 'my-parent-component',
  templateUrl: './parent.component.html',
  standalone: true,
  imports: [
    MyModule
  ]
})
export class ParentComponent {
  ...
}
Run Code Online (Sandbox Code Playgroud)

子组件位于另一个模块中——MyModule。my.module.ts 文件看起来像

/* imports */

@NgModule({
  declarations: [
    ChildComponent
  ],
  imports: [
    ...
  ]
})
export class MyModule { 
  constructor(entityDefinitionService: EntityDefinitionService) {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

但我父母的 HTML 给了我错误

    <child-component></child-component>    
Run Code Online (Sandbox Code Playgroud)

线 ...

'app-child-component' is not a known element:
1. If 'app-child-component' is an Angular component, then verify that it is included in the '@Component.imports' of this …
Run Code Online (Sandbox Code Playgroud)

javascript components module angular angular14

0
推荐指数
1
解决办法
1739
查看次数

如何计算字符串中的字母数?

我正在使用Ruby 2.4.如何计算字符串中的字母数?这将包括重音"a"之类的东西.例如,一个看起来像的字符串

"A."
Run Code Online (Sandbox Code Playgroud)

有一个"字母"和一个字符串

"123ABC"
Run Code Online (Sandbox Code Playgroud)

有三个.

ruby string count

-1
推荐指数
1
解决办法
619
查看次数

为什么我的过滤器对我的Python列表不起作用?

我正在使用Python 3.7。我想将正则表达式应用于列表中的每个元素。这是清单

>>> title_words 
['that', 'the', 'famous', 'ukulele', 'medley', '"somewhere', 'over', 'the', 'rainbow/what', 'a', 'wonderful', 'world"', 'by', 'israel', 'kamakawiwoê»ole', 'was', 'originally', 'recorded', 'in', 'a', 'completely', 'unplanned', 'session', 'at', '3:00', 'in', 'the', 'morning,', 'and', 'done', 'in', 'just', 'one', 'take.']
Run Code Online (Sandbox Code Playgroud)

我以为对列表运行过滤器可以解决问题,但请注意,当我运行时

>>> list(filter(lambda s: re.sub(r'^\W+|\W+$', '', s), title_words))
['that', 'the', 'famous', 'ukulele', 'medley', '"somewhere', 'over', 'the', 'rainbow/what', 'a', 'wonderful', 'world"', 'by', 'israel', 'kamakawiwoê»ole', 'was', 'originally', 'recorded', 'in', 'a', 'completely', 'unplanned', 'session', 'at', '3:00', 'in', 'the', 'morning,', 'and', 'done', 'in', 'just', 'one', 'take.'] …
Run Code Online (Sandbox Code Playgroud)

python arrays filter python-3.x

-1
推荐指数
1
解决办法
43
查看次数