0
Follow
0
View

pattern matching in Python with regex problem

daihua1213 注册会员
2023-01-25 20:46

In your example data you re using 2 types of hyphens.

If you want to match both you can make use of a character class [–-]

Apart from that, using .* repeats 0+ times any character (can match empty strings) and will first match until the end of the line and will allow backtracking to match the rest of the pattern.

What you could do it make the pattern a bit more precise starting each group matching at least a word character.

If you are only interested in the groups title, city and state you don't need the other 2 capture groups.

Note that if you want to match a space that you don't have to escape it.

^\W*(?P\w.*?) [–-] <a href="https://www.115kc.com/search/index.html?q=located">located</a> in (?P<city>\w.*?), (?P<state>\w.*)
</state></city>
  • ^ Start of string
  • \W* Match optional non word characters
  • (?P\w.*?)</code> Match a word character, followed by matching as least as possible chars</li> <li><code> [–-] </code> Match any of the dashes with a space to the left and right</li> <li><code>located in </code> Match literally</li> <li><code>(?P<city>\w.*?)</code> Match a word character followed by matching as least as possible chars</li> <li><code>, </code> Match literally</li> <li><code>(?P<state>\w.*)</code> Match a word character followed by the rest of the line</li> </ul> <p><a href="https://regex101.com/r/YJuxP5/1" rel="nofollow noreferrer">Regex demo</a> | <a href="https://ideone.com/ufjq4H" rel="nofollow noreferrer">Python demo</a></p> <p>Example</p> <pre><code>import re pattern = r"^\W*(?P<title>\w.*?) [–-] located in (?P<city>\w.*?), (?P<state>\w.*)" wiki = """There are several Buddhist universities in the United States. Some of these have existed for decades and are accredited. Others are relatively new and are either in the process of being accredited or else have no formal accreditation. The list includes: • Dhammakaya Open University – located in Azusa, California, • Dharmakirti College – located in Tucson, Arizona • Dharma Realm Buddhist University – located in Ukiah, California • Ewam Buddhist Institute – located in Arlee, Montana • Naropa University - located in Boulder, Colorado • Institute of Buddhist Studies – located in Berkeley, California • Maitripa College – located in Portland, Oregon • Soka University of America – located in Aliso Viejo, California • University of the West – located in Rosemead, California • Won Institute of Graduate Studies – located in Glenside, Pennsylvania""" for item in re.finditer(pattern, wiki, re.M): print(item.groupdict()) </code></pre> <p>Output</p> <pre><code>{'title': 'Dhammakaya Open University', 'city': 'Azusa', 'state': 'California,'} {'title': 'Dharmakirti College', 'city': 'Tucson', 'state': 'Arizona'} {'title': 'Dharma Realm Buddhist University', 'city': 'Ukiah', 'state': 'California'} {'title': 'Ewam Buddhist Institute', 'city': 'Arlee', 'state': 'Montana'} {'title': 'Naropa University', 'city': 'Boulder', 'state': 'Colorado'} {'title': 'Institute of Buddhist Studies', 'city': 'Berkeley', 'state': 'California'} {'title': 'Maitripa College', 'city': 'Portland', 'state': 'Oregon'} {'title': 'Soka University of America', 'city': 'Aliso Viejo', 'state': 'California'} {'title': 'University of the West', 'city': 'Rosemead', 'state': 'California'} {'title': 'Won Institute of Graduate Studies', 'city': 'Glenside', 'state': 'Pennsylvania'} </code></pre> </div> </div> <div class="aw-answer-show aw-alpha-hidden" style="display: none"> <span style="cursor: pointer;"><i class="icon-chevrons-down"></i> Read the full article</span> </div> <div class="aw-answer-hide aw-alpha-hidden mt-3" style="display: none;background:none;position: inherit;height: auto"> <span style="position: unset;float: left;cursor: pointer"><i class="icon-chevrons-up"></i> Fold</span> </div> </div> <!--回答操作--> <div class="answer-btn-actions mt-3"> <label class="mr-1"> <a href="javascript:;" class="aw-ajax-agree " onclick="AWS.User.agree(this,'answer','60945');"> <i class="icon-thumb_up"></i> Agree <span> 0</span> </a> </label> <label class="mr-3 "> <a href="javascript:;" class="aw-ajax-against " onclick="AWS.User.against(this,'answer','60945');"> <i class="icon-thumb_down"></i> </a> </label> <label class="mr-3"> <a href="javascript:;" class="answerCommentBtn" data-id="60945"> <i class="icon-chat"></i> <span class="answer-comment-count60945">0</span>Comment </a> </label> <div class="dropdown d-inline-block mr-3"> <a href="javascript:;" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-fw fa-share-alt font-9 d-sm-inline-block"></i>Share </a> <div class="dropdown-menu p-0 border-0 font-size-sm"> <div class="text-center d-block py-2" style="min-width: 100px"> <a href="javascript:;" class="dropdown-item aw-clipboard" data-clipboard-text="https://www.115kc.com/question-detail/52560-60945.html"><i class="icon-link"></i> 复制链接</a> <a href="javascript:;" onclick="AWS.User.share('pattern matching in Python with regex problem','https://www.115kc.com/question-detail/52560-60945.html','','weibo')" class="dropdown-item "><i class="fab fa-weibo text-warning"></i> 新浪微博</a> <a href="javascript:;" onclick="AWS.User.share('pattern matching in Python with regex problem','https://www.115kc.com/question-detail/52560-60945.html','','qzone')" class="dropdown-item "><i class="fab fa-qq text-primary"></i> 腾讯空间</a> <div class="aw-qrcode-container" data-share="https://www.115kc.com/question-detail/52560-60945.html"> <a href="javascript:;" class="dropdown-item "><i class="fab fa-weixin text-success"></i> 微信扫一扫</a> <div class="aw-qrcode text-center py-2"></div> </div> </div> </div> </div> <!--问题回答操作栏钩子--> <div class="aw-share clearfix d-inline-block"> <div class="social-share" data-disabled="google,twitter,facebook,linkedin,douban"></div> </div> </div> <!--评论框动态显示--> <div class="answerCommentBox mt-2 border" id="answerCommentBox-60945" style="display: none;margin-left: 45px"> <div class="answerCommentHeader clearfix px-3 pt-3"> <h6 class="font-10 float-left mb-1"><span class="answer-comment-count60945">0</span> Comment</h6> </div> <div class="answerCommentList px-3"></div> <div class="pageElement"></div> <div class="commentForm clearfix rounded aw-replay-box"></div> </div> </div> <div class="aw-answer-item p-3 mb-1 bg-white" id="question-answer-60943" data-answer-id="60943"> <div class="user-details-card pt-0 pb-2 position-relative clearfix"> <div class="user-details-card-avatar float-left" style="position: relative"> <a href="/people/potatobroth/" class="aw-username" data-id="567" title="potatobroth"> <img src="http://file.115kc.com/storage/avatar/aratar_566.jpg" class="rounded" onerror="this.src='/static/common/image/default-avatar.svg'" alt="potatobroth" style="width: 40px;height: 40px"> </a> </div> <div class="user-details-card-name float-left ml-2"> <a href="/people/potatobroth/" data-id="567" class="aw-username" title="potatobroth">potatobroth</a> <span class="badge badge-success">注册会员</span> <br><span class="ml-0"> 2023-01-25 20:46 </span> </div> </div> <div class="aw-content"> <div class="aw-answer-content overflow-hidden"> <div class="s-prose js-post-body" id="74671281" itemprop="text"> <p>Thanks to JustLearning, my problem is solved. <a href="https://www.115kc.com/search/index.html?q=re">re</a> is the code I ended up using. I can't believe it was a long hyphen instead of a short one. And now I know I dont need to use the re.VERBOSE. Thank you again</p> <p>pattern =re.compile( r'(?P.<em>)' r'(-\ <a href="https://www.115kc.com/search/index.html?q=located">located</a>\ in\ )' r'(?P.</em>)' r'(,\ )' r'(?P.*)')</p> </div> </div> <div class="aw-answer-show aw-alpha-hidden" style="display: none"> <span style="cursor: pointer;"><i class="icon-chevrons-down"></i> Read the full article</span> </div> <div class="aw-answer-hide aw-alpha-hidden mt-3" style="display: none;background:none;position: inherit;height: auto"> <span style="position: unset;float: left;cursor: pointer"><i class="icon-chevrons-up"></i> Fold</span> </div> </div> <!--回答操作--> <div class="answer-btn-actions mt-3"> <label class="mr-1"> <a href="javascript:;" class="aw-ajax-agree " onclick="AWS.User.agree(this,'answer','60943');"> <i class="icon-thumb_up"></i> Agree <span> 0</span> </a> </label> <label class="mr-3 "> <a href="javascript:;" class="aw-ajax-against " onclick="AWS.User.against(this,'answer','60943');"> <i class="icon-thumb_down"></i> </a> </label> <label class="mr-3"> <a href="javascript:;" class="answerCommentBtn" data-id="60943"> <i class="icon-chat"></i> <span class="answer-comment-count60943">0</span>Comment </a> </label> <div class="dropdown d-inline-block mr-3"> <a href="javascript:;" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-fw fa-share-alt font-9 d-sm-inline-block"></i>Share </a> <div class="dropdown-menu p-0 border-0 font-size-sm"> <div class="text-center d-block py-2" style="min-width: 100px"> <a href="javascript:;" class="dropdown-item aw-clipboard" data-clipboard-text="https://www.115kc.com/question-detail/52560-60943.html"><i class="icon-link"></i> 复制链接</a> <a href="javascript:;" onclick="AWS.User.share('pattern matching in Python with regex problem','https://www.115kc.com/question-detail/52560-60943.html','','weibo')" class="dropdown-item "><i class="fab fa-weibo text-warning"></i> 新浪微博</a> <a href="javascript:;" onclick="AWS.User.share('pattern matching in Python with regex problem','https://www.115kc.com/question-detail/52560-60943.html','','qzone')" class="dropdown-item "><i class="fab fa-qq text-primary"></i> 腾讯空间</a> <div class="aw-qrcode-container" data-share="https://www.115kc.com/question-detail/52560-60943.html"> <a href="javascript:;" class="dropdown-item "><i class="fab fa-weixin text-success"></i> 微信扫一扫</a> <div class="aw-qrcode text-center py-2"></div> </div> </div> </div> </div> <!--问题回答操作栏钩子--> <div class="aw-share clearfix d-inline-block"> <div class="social-share" data-disabled="google,twitter,facebook,linkedin,douban"></div> </div> </div> <!--评论框动态显示--> <div class="answerCommentBox mt-2 border" id="answerCommentBox-60943" style="display: none;margin-left: 45px"> <div class="answerCommentHeader clearfix px-3 pt-3"> <h6 class="font-10 float-left mb-1"><span class="answer-comment-count60943">0</span> Comment</h6> </div> <div class="answerCommentList px-3"></div> <div class="pageElement"></div> <div class="commentForm clearfix rounded aw-replay-box"></div> </div> </div> <div class="aw-answer-item p-3 mb-1 bg-white" id="question-answer-60944" data-answer-id="60944"> <div class="user-details-card pt-0 pb-2 position-relative clearfix"> <div class="user-details-card-avatar float-left" style="position: relative"> <a href="/people/dbwjik/" class="aw-username" data-id="394" title="dbwjik"> <img src="http://file.115kc.com/storage/avatar/aratar_393.jpg" class="rounded" onerror="this.src='/static/common/image/default-avatar.svg'" alt="dbwjik" style="width: 40px;height: 40px"> </a> </div> <div class="user-details-card-name float-left ml-2"> <a href="/people/dbwjik/" data-id="394" class="aw-username" title="dbwjik">dbwjik</a> <span class="badge badge-success">注册会员</span> <br><span class="ml-0"> 2023-01-25 20:46 </span> </div> </div> <div class="aw-content"> <div class="aw-answer-content overflow-hidden"> <div class="s-prose js-post-body" id="74670918" itemprop="text"> <p>In fact, for current versions of Python, you do not need to add <code><a href="https://www.115kc.com/search/index.html?q=re">re</a>.VERBOSE</code> at all. If you do</p> <pre><code>for item in re.finditer(pattern, wiki): print(item.groupdict()) </code></pre> <p>the program will print</p> <pre><code>{'title': '• Naropa University ', 'city': 'Boulder', 'state': 'Colorado '} </code></pre> <p>using Python 3.10.</p> <p>By the way, the program only outputs one school because the other schools use a long hyphen <code>–</code> instead or a short one, <code>-</code>. Making all schools use the same, and changing your <code>pattern</code> accordingly, should give you the whole list.</p> </div> </div> <div class="aw-answer-show aw-alpha-hidden" style="display: none"> <span style="cursor: pointer;"><i class="icon-chevrons-down"></i> Read the full article</span> </div> <div class="aw-answer-hide aw-alpha-hidden mt-3" style="display: none;background:none;position: inherit;height: auto"> <span style="position: unset;float: left;cursor: pointer"><i class="icon-chevrons-up"></i> Fold</span> </div> </div> <!--回答操作--> <div class="answer-btn-actions mt-3"> <label class="mr-1"> <a href="javascript:;" class="aw-ajax-agree " onclick="AWS.User.agree(this,'answer','60944');"> <i class="icon-thumb_up"></i> Agree <span> 0</span> </a> </label> <label class="mr-3 "> <a href="javascript:;" class="aw-ajax-against " onclick="AWS.User.against(this,'answer','60944');"> <i class="icon-thumb_down"></i> </a> </label> <label class="mr-3"> <a href="javascript:;" class="answerCommentBtn" data-id="60944"> <i class="icon-chat"></i> <span class="answer-comment-count60944">0</span>Comment </a> </label> <div class="dropdown d-inline-block mr-3"> <a href="javascript:;" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-fw fa-share-alt font-9 d-sm-inline-block"></i>Share </a> <div class="dropdown-menu p-0 border-0 font-size-sm"> <div class="text-center d-block py-2" style="min-width: 100px"> <a href="javascript:;" class="dropdown-item aw-clipboard" data-clipboard-text="https://www.115kc.com/question-detail/52560-60944.html"><i class="icon-link"></i> 复制链接</a> <a href="javascript:;" onclick="AWS.User.share('pattern matching in Python with regex problem','https://www.115kc.com/question-detail/52560-60944.html','','weibo')" class="dropdown-item "><i class="fab fa-weibo text-warning"></i> 新浪微博</a> <a href="javascript:;" onclick="AWS.User.share('pattern matching in Python with regex problem','https://www.115kc.com/question-detail/52560-60944.html','','qzone')" class="dropdown-item "><i class="fab fa-qq text-primary"></i> 腾讯空间</a> <div class="aw-qrcode-container" data-share="https://www.115kc.com/question-detail/52560-60944.html"> <a href="javascript:;" class="dropdown-item "><i class="fab fa-weixin text-success"></i> 微信扫一扫</a> <div class="aw-qrcode text-center py-2"></div> </div> </div> </div> </div> <!--问题回答操作栏钩子--> <div class="aw-share clearfix d-inline-block"> <div class="social-share" data-disabled="google,twitter,facebook,linkedin,douban"></div> </div> </div> <!--评论框动态显示--> <div class="answerCommentBox mt-2 border" id="answerCommentBox-60944" style="display: none;margin-left: 45px"> <div class="answerCommentHeader clearfix px-3 pt-3"> <h6 class="font-10 float-left mb-1"><span class="answer-comment-count60944">0</span> Comment</h6> </div> <div class="answerCommentList px-3"></div> <div class="pageElement"></div> <div class="commentForm clearfix rounded aw-replay-box"></div> </div> </div> </div> </div> </div> <div class="aw-right col-md-3 px-xs-0"> <div class="r-box mb-1"> <div class="r-title"> <h4>About the Author</h4> </div> <div class="block-content"> <dl class="overflow-hidden mb-0 pb-2 border-bottom"> <dt class="float-left"> <a href="/people/ucdosucdos/" data-pjax="pageMain" class="aw-username" data-id="581"> <img src="http://file.115kc.com/storage/avatar/aratar_580.jpg" class="rounded" width="45" height="45"> </a> </dt> <dd class="float-right" style="width:calc(100% - 55px)"> <a href="/people/ucdosucdos/" class="d-block aw-one-line aw-username" data-id="581" target="_blank"> <strong>ucdosucdos</strong> <span class="badge badge-success">注册会员</span> </a> <p class="mb-0 font-8 text-muted aw-one-line">这家伙很懒,什么都没留下...</p> </dd> </dl> <div class="d-flex text-center pt-3 pb-3 text-muted"> <a href="/people/ucdosucdos/answer.html" target="_blank" class="flex-fill mb-0"> <dl class="mb-0"> <dt>0</dt> <dd>Answer</dd> </dl> </a> <a href="/people/ucdosucdos/article.html" target="_blank" class="flex-fill mb-0"> <dl class="mb-0"> <dt>0</dt> <dd>Article</dd> </dl> </a> <a href="/people/ucdosucdos/question.html" target="_blank" class="flex-fill mb-0"> <dl class="mb-0"> <dt>0</dt> <dd>Question</dd> </dl> </a> </div> </div> </div> <div class="r-box mb-2"> <div class="r-title"> <h4>Question Info</h4> </div> <div class="block-content"> <div class="text-center text-muted"> <dl class="clearfix mb-0"> <dt class="float-left">Publish Time</dt> <dd class="float-right">2023-01-25 20:46</dd> </dl> <dl class="clearfix"> <dt class="float-left">Update Time</dt> <dd class="float-right">2023-01-25 20:46</dd> </dl> </div> </div> </div> <div class="r-box mb-2"> <div class="r-title"> <h4>Related Question</h4> </div> <div class="aboutanswer"> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/55031.html">安卓的内容提供者底层用binder实现,binder已经实现了进程间通信,为啥还需要内容提供者?</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">0 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/21061.html">ERCOT API:使用Python发送带有签名和二进制安全令牌的SOAP XML</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">3 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/50696.html">被请求的资源上没有'Access-Control-Allow-Origin'标头.如何修复此错误[重复]</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">2 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/39318.html">配置yum出问题了 是什么问题(操作系统-linux)</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">1 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/15783.html">pycharm运行python程序会自动打开命令行模式,如图,只是输出123,如何恢复成正常的情况?</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">7 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/17685.html">只能加入一个可迭代错误的shell scrapy上的python刮</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">5 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/56886.html">Eslint不尊重类属性的缩进</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">0 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/18667.html">NoSuchElementException . python文本框</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">3 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/59884.html">windows server 桌面体验安装失败</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">0 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> <dl class="mb-0 py-2"> <h2 class="d-block aw-one-line font-weight-normal font-9"> <a href="/question-detail/20798.html">为什么头文件已经加上了string,还是说没有定义</a> </h2> <dd class="mt-2 text-color-info mb-0"> <label class="mr-2 mb-0">1 View</label> <label class="mr-2 mb-0">0 Follow</label> <label class="mr-2 mb-0">0 Answer</label> <label class="mb-0">0 Comment</label> </dd> </dl> </div> </div> </div> </div> </div> </div> </div> <!--全局页面内容底部钩子--> <div class="foot"> <div class="container justify-content-center"> <div class="py-3 footauto clearfix"> <div class="float-left ">115KC © 2023 <a target="_blank" class="ml-3" rel="nofollow noopener noreferrer" href="https://beian.miit.gov.cn/">闽ICP备2020022241号</a></div> <div class="float-right"> <ul> <li class="d-inline-block mx-1"><a href="/page/index.html?url_name=contact" title="联系我们" target="_blank">联系我们</a></li> <li class="d-inline-block mx-1"><a href="https://www.115kc.com/sitemap.xml" title="网站地图" target="_blank">SiteMap</a></li> </ul> </div> </div> </div> </div> <a class="aw-back-top hidden-xs" href="javascript:;" onclick="$.scrollTo(1, 600, {queue:true});"><i class="icon-arrow-up-circle"></i></a> <script> //导航悬浮 var topMain = $(".navbox").height(); $(window).scroll(function(){ if ($(window).scrollTop()>topMain + 200){ $('.navbox').addClass('suspension'); } else { $('.navbox').removeClass('suspension'); } //更换logo if($('.navbox').hasClass('suspension')){ $(".logoimg").attr('src',"/storage/common/20221108/038174ec393631d2f058d555c6ca9959.png"); }else( $(".logoimg").attr('src',"https://www.115kc.com/templates/default/static/images/logo-write.png") ) }); $('.friend-link').removeAttr('rel'); </script> <div id="aw-ajax-box"></div> <!--自动加载js文件--> <script src="/templates/default/static/js/question/detail.js"></script> <!--全局自定义底部html--> <script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script> <script>LA.init({id: "JsGaNvG3mca123w0",ck: "JsGaNvG3mca123w0"})</script> <script> $(document).ready(function () { var openEnable="Y"; var answerId = parseInt("0"); var showAll = $('#show-all'); if(openEnable==='Y') { $('.aw-question-show').click(); $('.aw-answer-show').click(); if(showAll.height() >= 120) { $('.aw-question-hide').show(); } }else{ if(showAll.height() >= 120) { showAll.show().css('height','120px'); $('.aw-question-show').show(); } } $(document).on('click', '.aw-question-show', function (e) { $('.aw-question-show').hide(); showAll.show().css('height','auto'); $('.aw-question-hide').show(); }); $(document).on('click', '.aw-question-hide', function (e) { $('.aw-question-hide').hide(); showAll.show().css('height','120px'); $('.aw-question-show').show(); }); $('.aw-answer-item .aw-answer-content').each(function(){ if($(this).height() >= 200) { if(openEnable==='Y') { $(this).css('height','auto'); $(this).parents('.aw-answer-item').find('.aw-answer-hide').show(); }else{ if(answerId) { $(this).css('height','auto'); $(this).parents('.aw-answer-item').find('.aw-answer-hide').show(); }else{ $(this).css('height','200px'); $(this).parents('.aw-answer-item').find('.aw-answer-show').show(); } } } }); $(document).on('click', '.aw-answer-show', function (e) { $(this).hide(); $(this).parents('.aw-answer-item').find('.aw-answer-content').show().css('height','auto'); $(this).parents('.aw-answer-item').find('.aw-answer-hide').show(); }); $(document).on('click', '.aw-answer-hide', function (e) { $(this).hide(); $(this).parents('.aw-answer-item').find('.aw-answer-content').show().css('height','200px'); $(this).parents('.aw-answer-item').find('.aw-answer-show').show(); }); //右边内容错位 let parent=$(".aw-left").parent(); let html=$(".aw-left .aw-right").prop("outerHTML"); if (html){ parent.append(html); $(".aw-left .aw-right").empty(); } }); </script> <style> .aw-list-img{width:100%;height: auto;display: flex;} </style> <form id="attach-download-form" action="/upload/download.html" method="post"> <input type="hidden" id="attach-name" name="name" value=""> <input type="hidden" id="attachType" name="type" value="0"> </form> </body> </html>